Skip to content

Commit

Permalink
fixed the usage of configs use set than update as update duplicates t…
Browse files Browse the repository at this point in the history
…he buttons
  • Loading branch information
fonsekaean committed Nov 2, 2017
1 parent 90dd9a6 commit 16c1aa9
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/forms/MarkdownEditorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
/**
Expand All @@ -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;
}

Expand Down

0 comments on commit 16c1aa9

Please sign in to comment.