From 44c136da6d7d5440b84e55e988920a23dd5e956d Mon Sep 17 00:00:00 2001 From: Simon Guionniere Date: Thu, 19 Nov 2020 10:35:47 +0100 Subject: [PATCH] Revert "Merge pull request #117 from mpoiriert/FIX-17-integrate-froala-with-sonata" This reverts commit 756bf869ddb4506ef3b67968a5900e8c99a2241d, reversing changes made to 65363b6fbcb6b132a6d22621f6adf957dd051a7c. --- Form/Type/FroalaEditorType.php | 54 ++++------ Resources/views/Form/froala_widget.html.twig | 103 +++++++++---------- 2 files changed, 67 insertions(+), 90 deletions(-) diff --git a/Form/Type/FroalaEditorType.php b/Form/Type/FroalaEditorType.php index 8b4f73ab..7f193bf5 100644 --- a/Form/Type/FroalaEditorType.php +++ b/Form/Type/FroalaEditorType.php @@ -72,10 +72,7 @@ public function buildForm( FormBuilderInterface $p_builder, array $p_options ) foreach( $p_options as $key => $option ) { - if(0 !== strpos($key, 'froala_')) { - continue; - } - $p_builder->setAttribute( $key, $option ); + $p_builder->setAttribute( $key, $option ); } } @@ -86,21 +83,13 @@ public function buildForm( FormBuilderInterface $p_builder, array $p_options ) */ public function buildView( FormView $p_view, FormInterface $p_form, array $p_options ) { - $p_options = array_filter( - $p_options, - function ($key) { - return strpos($key, 'froala_') === 0; - }, - ARRAY_FILTER_USE_KEY - ); - $arrKey = UConfiguration::getArrOption(); $arrKeyCustom = UConfiguration::getArrOptionCustom(); $arrOption = array(); - $arrPluginEnabled = isset( $p_options [ "froala_pluginsEnabled" ] ) ? $p_options [ "froala_pluginsEnabled" ] : array(); - $arrPluginDisabled = isset( $p_options [ "froala_pluginsDisabled" ] ) ? $p_options [ "froala_pluginsDisabled" ] : array(); - $arrEvent = isset( $p_options [ "froala_events" ] ) ? $p_options [ "froala_events" ] : array(); - $profile = isset( $p_options [ "froala_profile" ] ) ? $p_options [ "froala_profile" ] : null; + $arrPluginEnabled = isset( $p_options [ "pluginsEnabled" ] ) ? $p_options [ "pluginsEnabled" ] : array(); + $arrPluginDisabled = isset( $p_options [ "pluginsDisabled" ] ) ? $p_options [ "pluginsDisabled" ] : array(); + $arrEvent = isset( $p_options [ "events" ] ) ? $p_options [ "events" ] : array(); + $profile = isset( $p_options [ "profile" ] ) ? $p_options [ "profile" ] : null; // ------------------------- DECLARE ---------------------------// if( $profile && $this->parameterBag->has( Configuration::$NODE_ROOT . '.profiles' ) ) @@ -111,9 +100,7 @@ function ($key) { if( array_key_exists( $profile, $profiles ) ) { $profileConfig = $profiles[ $profile ]; - foreach($profileConfig as $profileKey => $profileOption) { - $p_options['froala_' . $profileKey] = $profileOption; - } + $p_options = array_merge( $p_options, $profileConfig ); } else { @@ -126,16 +113,11 @@ function ($key) { } - $finalOptions = []; - foreach($p_options as $key => $value) { - $finalOptions[substr($key, strlen('froala_'))] = $value; - } - // Prepare options. - $this->m_optionManager->prepareOptions( $finalOptions ); + $this->m_optionManager->prepareOptions( $p_options ); // Separate Froala options from custom, to iterate properly in twig widget. - foreach( $finalOptions as $key => $option ) + foreach( $p_options as $key => $option ) { if( in_array( $key, $arrKey ) ) { @@ -145,25 +127,25 @@ function ($key) { { if( in_array( $key, $arrKeyCustom ) ) { - $p_view->vars [ 'froala_' . $key ] = $option; + $p_view->vars [ $key ] = $option; } } } // Options. - $p_view->vars [ "froala_arrOption" ] = $arrOption; + $p_view->vars [ "arrOption" ] = $arrOption; // Plugins. $arrPlugin = $this->m_pluginProvider->obtainArrPluginToInclude( $arrPluginEnabled, // $arrPluginDisabled ); - $p_view->vars [ "froala_arrOption" ][ "pluginsEnabled" ] = + $p_view->vars [ "arrOption" ][ "pluginsEnabled" ] = $this->m_pluginProvider->obtainArrPluginCamelized( $arrPlugin ); - $p_view->vars [ "froala_arrPluginJS" ] = + $p_view->vars [ "arrPluginJS" ] = $this->m_pluginProvider->obtainArrPluginJS( $arrPlugin ); - $p_view->vars [ "froala_arrPluginCSS" ] = + $p_view->vars [ "arrPluginCSS" ] = $this->m_pluginProvider->obtainArrPluginCSS( $arrPlugin ); - $p_view->vars [ "froala_events" ] = $arrEvent; + $p_view->vars [ "events" ] = $arrEvent; } /** @@ -177,21 +159,21 @@ public function configureOptions( OptionsResolver $p_resolver ) foreach( UConfiguration::getArrOptionAll() as $option ) { - $optionName = 'froala_' . $option; + // If defined in config file, set default value to form, else set option as available. if( $this->parameterBag->has( Configuration::$NODE_ROOT . '.' . $option ) ) { - $arrDefault[ $optionName ] = + $arrDefault[ $option ] = $this->parameterBag->get( Configuration::$NODE_ROOT . '.' . $option ); } else { - $arrDefined[] = $optionName; + $arrDefined[] = $option; } } - $arrDefined[] = 'froala_profile'; + $arrDefined[] = 'profile'; $p_resolver->setDefined( $arrDefined ); $p_resolver->setDefaults( $arrDefault ); diff --git a/Resources/views/Form/froala_widget.html.twig b/Resources/views/Form/froala_widget.html.twig index 571860ef..7c118d7e 100644 --- a/Resources/views/Form/froala_widget.html.twig +++ b/Resources/views/Form/froala_widget.html.twig @@ -2,23 +2,23 @@ {% block froala_widget %} {# CSS. #} - {% if froala_includeFontAwesome %} + {% if includeFontAwesome %} {% endif %} - {% if froala_includeCodeMirror %} + {% if includeCodeMirror %} {% endif %} - {% if froala_includeCSS %} - - + {% if includeCSS %} + + - {% if froala_arrOption[ "theme" ] is defined %} - + {% if arrOption[ "theme" ] is defined %} + {% endif %} - {% for plugin in froala_arrPluginCSS %} - + {% for plugin in arrPluginCSS %} + {% endfor %} {% endif %} @@ -28,26 +28,26 @@ {# JS. #} - {% if froala_includeCodeMirror %} + {% if includeCodeMirror %} {% endif %} - {% if froala_includeJS %} + {% if includeJS %} - + - + - {% for plugin in froala_arrPluginJS %} - + {% for plugin in arrPluginJS %} + {% endfor %} {% endif %} - {% if froala_customJS is defined %} + {% if customJS is defined %} {% endif %} @@ -55,46 +55,41 @@ {% endblock %}