Skip to content

Commit

Permalink
Revert "Merge pull request #117 from mpoiriert/FIX-17-integrate-froal…
Browse files Browse the repository at this point in the history
…a-with-sonata"

This reverts commit 756bf86, reversing
changes made to 65363b6.
  • Loading branch information
sguionni committed Nov 19, 2020
1 parent a68b246 commit 44c136d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 90 deletions.
54 changes: 18 additions & 36 deletions Form/Type/FroalaEditorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand All @@ -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' ) )
Expand All @@ -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
{
Expand All @@ -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 ) )
{
Expand All @@ -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;
}

/**
Expand All @@ -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 );

Expand Down
103 changes: 49 additions & 54 deletions Resources/views/Form/froala_widget.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
{% block froala_widget %}

{# CSS. #}
{% if froala_includeFontAwesome %}
{% if includeFontAwesome %}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
{% endif %}
{% if froala_includeCodeMirror %}
{% if includeCodeMirror %}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.css" />
{% endif %}

{% if froala_includeCSS %}
<link rel="stylesheet" type="text/css" href="{{ asset( froala_basePath ~ 'css/froala_editor.pkgd.min.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ asset( froala_basePath ~ 'css/froala_style.min.css' ) }}" />
{% if includeCSS %}
<link rel="stylesheet" type="text/css" href="{{ asset( basePath ~ 'css/froala_editor.pkgd.min.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ asset( basePath ~ 'css/froala_style.min.css' ) }}" />

{% if froala_arrOption[ "theme" ] is defined %}
<link rel="stylesheet" type="text/css" href="{{ asset( froala_basePath ~ 'css/themes/' ~ froala_arrOption[ "theme" ] ~ '.min.css' ) }}" />
{% if arrOption[ "theme" ] is defined %}
<link rel="stylesheet" type="text/css" href="{{ asset( basePath ~ 'css/themes/' ~ arrOption[ "theme" ] ~ '.min.css' ) }}" />
{% endif %}

{% for plugin in froala_arrPluginCSS %}
<link rel="stylesheet" type="text/css" href="{{ asset( froala_basePath ~ 'css/' ~ froala_plugin ~ '.min.css' ) }}" />
{% for plugin in arrPluginCSS %}
<link rel="stylesheet" type="text/css" href="{{ asset( basePath ~ 'css/' ~ plugin ~ '.min.css' ) }}" />
{% endfor %}

{% endif %}
Expand All @@ -28,73 +28,68 @@

{# JS. #}

{% if froala_includeCodeMirror %}
{% if includeCodeMirror %}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/codemirror.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.3.0/mode/xml/xml.min.js"></script>
{% endif %}

{% if froala_includeJS %}
{% if includeJS %}
<script type="text/javascript" src="{{ asset( "bundles/kmsfroalaeditor/misc.js" ) }}"></script>
<script type="text/javascript" src="{{ asset( froala_basePath ~ 'js/froala_editor.pkgd.min.js' ) }}"></script>
<script type="text/javascript" src="{{ asset( basePath ~ 'js/froala_editor.pkgd.min.js' ) }}"></script>

<!--[if lt IE 9]>
<script type="text/javascript" src="{{ asset( froala_basePath ~ 'js/froala_editor_ie8.min.js' ) }}"></script>
<script type="text/javascript" src="{{ asset( basePath ~ 'js/froala_editor_ie8.min.js' ) }}"></script>
<![endif]-->
<script type="text/javascript" src="{{ asset( froala_basePath ~ 'js/languages/' ~ froala_arrOption.language ~ '.js' ) }}"></script>
<script type="text/javascript" src="{{ asset( basePath ~ 'js/languages/' ~ arrOption.language ~ '.js' ) }}"></script>

{% for plugin in froala_arrPluginJS %}
<script type="text/javascript" src="{{ asset( froala_basePath ~ 'js/' ~ plugin ~ '.min.js' ) }}"></script>
{% for plugin in arrPluginJS %}
<script type="text/javascript" src="{{ asset( basePath ~ 'js/' ~ plugin ~ '.min.js' ) }}"></script>
{% endfor %}
{% endif %}

{% if froala_customJS is defined %}
{% if customJS is defined %}
<script type="text/javascript" src="{{ asset( customJS ) }}"></script>
{% endif %}

{# Load the editor. #}
<script type="text/javascript">
{# Go. #}
const {{ id }}_function = function() {
document.addEventListener("DOMContentLoaded", function() {
(function(){
const editInstance = new FroalaEditor( "#{{ id }}",{
{# Add license. #}
{% if froala_serialNumber is defined %}
key : "{{ froala_serialNumber }}",
{% endif %}
{% for option, value in froala_arrOption %}
{{ option }} : {% include "@KMSFroalaEditor/Form/value.html.twig" %}
{% endfor %}
events: {
'image.error': function ( error ) {
froalaDisplayError( this, error );
},
'imageManager.error': function ( error ) {
froalaDisplayError( this, error );
},
'save.error': function ( error ) {
froalaDisplayError( this, error );
},
'file.error': function ( error, responses ) {
froalaDisplayError( this, error );
},
'video.error': function ( error, responses ) {
froalaDisplayError( this, error );
}
{% for event, func in froala_events %}
,'{{ event }}': {{ func }}
{% endfor %}
}})
})();
}
document.addEventListener("DOMContentLoaded", {{ id }}_function);
if (document.readyState === "interactive" || document.readyState === "complete" ) {
{{ id }}_function();
}
{% if serialNumber is defined %}
key : "{{ serialNumber }}",
{% endif %}
{% for option, value in arrOption %}
{{ option }} : {% include "@KMSFroalaEditor/Form/value.html.twig" %}
{% endfor %}
events: {
'image.error': function ( error ) {
froalaDisplayError( this, error );
},
'imageManager.error': function ( error ) {
froalaDisplayError( this, error );
},
'save.error': function ( error ) {
froalaDisplayError( this, error );
},
'file.error': function ( error, responses ) {
froalaDisplayError( this, error );
},
'video.error': function ( error, responses ) {
froalaDisplayError( this, error );
}
{% for event, func in events %}
,'{{ event }}': {{ func }}
{% endfor %}
}})
})();
});
</script>

{% endblock %}

0 comments on commit 44c136d

Please sign in to comment.