From 16c1aa9a301848eedc6bfbd49d0981756ecd0955 Mon Sep 17 00:00:00 2001 From: Nivanka Fonseka Date: Thu, 2 Nov 2017 17:40:30 +0530 Subject: [PATCH] fixed the usage of configs use set than update as update duplicates the buttons --- src/forms/MarkdownEditorConfig.php | 32 ++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/forms/MarkdownEditorConfig.php b/src/forms/MarkdownEditorConfig.php index 36dd3e0..e6ad320 100644 --- a/src/forms/MarkdownEditorConfig.php +++ b/src/forms/MarkdownEditorConfig.php @@ -73,6 +73,12 @@ public static function get($identifier = null) // Create new instance if unconfigured if (!isset(self::$configs[$identifier])) { self::$configs[$identifier] = static::create()->setIdentifier($identifier); + $settings = static::config()->get('settings'); + if(!isset($settings[$identifier])){ + $default = static::config()->get('default_config'); + $settings[$identifier] = $settings[$default]; + static::config()->set('settings', $settings); + } } return self::$configs[$identifier]; @@ -179,10 +185,9 @@ public function getEditorCSS() public function getSettings() { $settings = static::config()->get('settings'); - $config = static::get_active_identifier(); $toolbar = null; - if (isset($settings[$config])) { - $toolbar = $settings[$config]; + if (isset($settings[$this->getIdentifier()])) { + $toolbar = $settings[$this->getIdentifier()]; } else { // Config not found, return default @@ -202,15 +207,10 @@ public function getSettings() */ public function addSeparator() { + $settings = static::config()->get('settings'); - $active = static::get_active_identifier(); - if (is_array($settings[$active])) { - $settings[$active][] = '|'; - } else { - $default = static::config()->get('default_config'); - $settings[$default][] = '|'; - } - static::config()->update('settings', $settings); + $settings[$this->getIdentifier()][] = '|'; + static::config()->set('settings', $settings); return $this; } /** @@ -220,14 +220,8 @@ public function addSeparator() public function addButton($button) { $settings = static::config()->get('settings'); - $active = static::get_active_identifier(); - if (is_array($settings[$active])) { - $settings[$active][] = $button; - } else { - $default = static::config()->get('default_config'); - $settings[$default][] = $button; - } - static::config()->update('settings', $settings); + $settings[$this->getIdentifier()][] = $button; + static::config()->set('settings', $settings); return $this; }