Skip to content

Commit

Permalink
Merge pull request #2 from antoniocambados/master
Browse files Browse the repository at this point in the history
Thanks @antoniocambados sorry for very late! There are no any notify to me -- from github. :/
  • Loading branch information
liverbool authored Oct 8, 2018
2 parents cc2cd70 + 1fb6648 commit c148e4f
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/Form/Type/AceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'maxLines' => 100,
], $config);

$config['mode'] = $this->normalizeMode($config['mode'] ?? null);
$config['theme'] = $this->normalizeTheme($config['theme'] ?? null);

$builder->setAttribute('config', $config);
}

Expand Down Expand Up @@ -229,15 +232,15 @@ public function configureOptions(OptionsResolver $resolver)
return $value;
})
->setNormalizer('mode', function (Options $options, $value) {
if (null !== $value && false === strpos($value, '/')) {
$value = 'ace/mode/' . $value;
}

return $value;
return $this->normalizeMode($value);
})
->setNormalizer('config', function (Options $options, $value) {
if (empty($value['mode'])) {
$value['mode'] = $options['mode'];
$optionsMode = $this->normalizeMode($options['mode']);

if (!empty($value['mode'])) {
$value['mode'] = $this->normalizeMode($value['mode']);
} elseif ($optionsMode !== null) {
$value['mode'] = $optionsMode;
}

return $value;
Expand Down Expand Up @@ -267,4 +270,32 @@ public function getBlockPrefix()
{
return 'ace';
}

/**
* @param string $mode
*
* @return string|null
*/
protected function normalizeMode($mode)
{
if (null !== $mode && false === strpos($mode, '/')) {
$mode = 'ace/mode/' . $mode;
}

return $mode;
}

/**
* @param string $theme
*
* @return string|null
*/
protected function normalizeTheme($theme)
{
if (null !== $theme && false === strpos($theme, '/')) {
$theme = 'ace/theme/' . $theme;
}

return $theme;
}
}

0 comments on commit c148e4f

Please sign in to comment.