Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tinymce icons custom svg #261

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
10454b5
Change getting request service
LogansUA Apr 18, 2016
1a710d0
Merge pull request #193 from stfalcon/fix-using-request-service
LogansUA Apr 18, 2016
7f5e753
Small tweak to readme to reflect Symfony moving console to /bin/
SecondeJK Apr 28, 2016
fc86c99
Merge pull request #197 from SecondeJK/2.x
LogansUA Apr 28, 2016
c7f170d
Manage file_picker_callback option
LogansUA May 18, 2016
e547cb7
Merge pull request #199 from stfalcon/feature-file-picker-callback
LogansUA May 18, 2016
e008597
Update StfalconTinymceExtension.php
Sep 27, 2016
c349062
Merge pull request #208 from barik94/patch-2
LogansUA Sep 27, 2016
28f42d5
Merge pull request #232 from stfalcon/master
fre5h Dec 9, 2019
4ee2dc7
Merge pull request #241 from stfalcon/master
fre5h Dec 9, 2019
1e6d720
Upgrade to TinyMCE 5.3.2
magik092 Jun 16, 2020
670bca7
Add Form Type for TinyMCE
magik092 Jun 16, 2020
f1a466c
Implement ConfigManagerInterface
magik092 Jun 16, 2020
9db583a
Implement Textarea selector strategy
magik092 Jun 16, 2020
f012bf0
Handle initialization of textarea
magik092 Jun 16, 2020
a0a3783
Finalize plugin
magik092 Jun 25, 2020
0007811
Add simple mode TinyMCE
magik092 Jun 25, 2020
77a82ed
Custom configuration, async initial JS function
magik092 Jun 26, 2020
9ce5f30
Add variable plugin, advanced form type, fix async
magik092 Jun 26, 2020
9f31d62
Advanced variable plugin
magik092 Jun 29, 2020
b4eb2fc
Count words PL translation
magik092 Jun 29, 2020
488c39a
Textarea selector fix
magik092 Jun 29, 2020
7f6a39f
Enable native spell checking
magik092 Jul 3, 2020
0ec9ee8
Some default options
magik092 Jul 3, 2020
1a9a712
Provide valid_children and extended_valid_elements option
magik092 Jul 21, 2020
0d22f5c
Add entity_encoding option
magik092 Sep 1, 2020
25cef01
Upgrade loaded version of init.standard.js
magik092 Sep 1, 2020
739d8be
Add valid_elements to available options
magik092 Mar 29, 2022
95f1adb
Fix. always overwrite variable style in content_style
magik092 Jul 1, 2022
4766112
Change getting request service
LogansUA Apr 18, 2016
38fa4bb
Add Form Type for TinyMCE
magik092 Jun 16, 2020
0492d10
Implement ConfigManagerInterface
magik092 Jun 16, 2020
78bea95
Implement Textarea selector strategy
magik092 Jun 16, 2020
4d8f0fe
Handle initialization of textarea
magik092 Jun 16, 2020
79dc709
Finalize plugin
magik092 Jun 25, 2020
8209c54
Add simple mode TinyMCE
magik092 Jun 25, 2020
59bd71a
Custom configuration, async initial JS function
magik092 Jun 26, 2020
2690215
Add variable plugin, advanced form type, fix async
magik092 Jun 26, 2020
403ea2a
Advanced variable plugin
magik092 Jun 29, 2020
a3d42d0
Count words PL translation
magik092 Jun 29, 2020
b4ba011
Some default options
magik092 Jul 3, 2020
a72d7a1
Provide valid_children and extended_valid_elements option
magik092 Jul 21, 2020
9d1a671
Add entity_encoding option
magik092 Sep 1, 2020
76a3b27
Upgrade loaded version of init.standard.js
magik092 Sep 1, 2020
46e8783
Add valid_elements to available options
magik092 Mar 29, 2022
3133f85
Sync to 2.x
magik092 Aug 25, 2022
467958e
Merge remote-tracking branch 'origin/master'
magik092 Aug 25, 2022
e90c360
Fix entity_encoding Configuration key
magik092 Aug 25, 2022
44b7ea4
Custom toolbar button
Apr 11, 2023
2a6cd84
Merge pull request #1 from web-com-pl/tinymceButtons
Morphi81 Apr 11, 2023
de14fbe
:sparkles: add icons
Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*~
/vendor/
.idea
composer.lock
20 changes: 20 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 86 additions & 33 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,112 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$defaults = $this->getTinymceDefaults();

$treeBuilder = new TreeBuilder();
$treeBuilder = new TreeBuilder("TinyMCEBundle");

return $treeBuilder
->root('stfalcon_tinymce', 'array')
->root('tinymce', 'array')
->children()
// Include jQuery (true) library or not (false)
->booleanNode('include_jquery')->defaultFalse()->end()
// Use jQuery (true) or standalone (false) build of the TinyMCE
->booleanNode('tinymce_jquery')->defaultFalse()->end()
// Default language for all instances of the editor
->scalarNode('language')->defaultNull()->end()
// Default config name
->scalarNode('config_name')->defaultValue('default')->end()
// Selector
->scalarNode('selector')->defaultValue('[data-tinymce]')->end()
// Set init to true to use callback on the event init
->booleanNode('use_callback_tinymce_init')->defaultFalse()->end()
// Selector
->scalarNode('selector')->defaultValue('.tinymce')->end()
// base url for content
->scalarNode('base_url')->end()
// asset packageName
->scalarNode('asset_package_name')->end()
// Default language for all instances of the editor
->scalarNode('language')->defaultNull()->end()
->arrayNode('theme')
->useAttributeAsKey('name')
->prototype('array')
->useAttributeAsKey('name')
->prototype('variable')->end()
// content style
->scalarNode('content_style')->defaultValue('')->end()
// valid html elements
->scalarNode('valid_elements')->end()
// plugins
->scalarNode('plugins')->defaultValue('')->end()
// character encoding
->scalarNode('entity_encoding')->defaultValue('raw')->end()
// extended valid elements (tags)
->scalarNode('extended_valid_elements')->defaultValue('')->end()
// extended valid elements for tags (tags in tags)
->scalarNode('valid_children')->defaultValue('')->end()
// toolbar
->scalarNode('toolbar')->defaultValue('undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent')->end()
->scalarNode('quickbars_selection_toolbar')->defaultValue('')->end()
->scalarNode('quickbars_insert_toolbar')->defaultValue('')->end()
->booleanNode('relative_urls')->defaultFalse()->end()
->booleanNode('remove_script_host')->defaultFalse()->end()
->booleanNode('convert_urls')->defaultFalse()->end()
->booleanNode('browser_spellcheck')->defaultTrue()->end()
->arrayNode('file_picker')
->children()
->scalarNode('engine')->defaultNull()->end()
->scalarNode('name')->defaultNull()->end()
->scalarNode('route')->defaultNull()->end()
->arrayNode('route_parameters')
->prototype('scalar')->end()
->end()
->end()
// Add default theme if it doesn't set
->defaultValue($defaults)
->end()
// Configure custom TinyMCE buttons
->arrayNode('tinymce_buttons')
->useAttributeAsKey('name')
->prototype('array')
->addDefaultsIfNotSet()
->children()
->scalarNode('text')->defaultNull()->end()
->scalarNode('title')->defaultNull()->end()
->scalarNode('image')->defaultNull()->end()
->scalarNode('icon')->defaultNull()->end()
->arrayNode('file_browser')
->children()
->scalarNode('engine')->defaultNull()->end()
->scalarNode('name')->defaultNull()->end()
->scalarNode('route')->defaultNull()->end()
->arrayNode('route_parameters')
->prototype('scalar')->end()
->end()
->end()
->end()
->scalarNode('variable_prefix')->defaultValue('{{')->end()
->scalarNode('variable_suffix')->defaultValue('}}')->end()
// allow paste images into editor
->booleanNode('paste_data_images')->defaultTrue()->end()
->arrayNode('variables')
->children()
->scalarNode('title')->defaultNull()->end()
->arrayNode('list')
->prototype('scalar')->end()
->end()
->end()
->end()
// Configure external TinyMCE plugins
->arrayNode('external_plugins')
->arrayNode('theme')
->useAttributeAsKey('name')
->prototype('array')
->prototype('array')
->addDefaultsIfNotSet()
->children()
->scalarNode('url')->isRequired()->end()
->scalarNode('toolbar')->defaultNull()->end()
->scalarNode('quickbars_selection_toolbar')->defaultNull()->end()
->scalarNode('quickbars_insert_toolbar')->defaultNull()->end()
->end()
->end()
->end()

// Configure custom TinyMCE buttons
->arrayNode('tinymce_buttons')
->useAttributeAsKey('name')
->prototype('array')
->addDefaultsIfNotSet()
->children()
->scalarNode('text')->defaultNull()->end()
->scalarNode('tooltip')->defaultNull()->end()
->scalarNode('icon')->defaultNull()->end()
->end()
->end()
->end()

//custom icons svg
->arrayNode('tinymce_icons')
->useAttributeAsKey('name')
->prototype('array')
->addDefaultsIfNotSet()
->children()
->scalarNode('name_icon')->defaultNull()->end()
->scalarNode('svg_data')->defaultNull()->end()
->end()
->end()
->end()

->end()
->end();
}
Expand Down
163 changes: 163 additions & 0 deletions Form/Type/TinyMCEType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

namespace Stfalcon\Bundle\TinymceBundle\Form\Type;

use Stfalcon\Bundle\TinymceBundle\Model\ConfigManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class TinyMCEType
* @author Łukasz Wątor
*/
class TinyMCEType extends AbstractType
{
/** @var ConfigManagerInterface */
private $configManager;

/** @var bool */
private $enable = true;

/** @var int */
private static $id = 1;

public function __construct(ConfigManagerInterface $configManager)
{
$this->configManager = $configManager;
}

/**
* @param bool|null $isEnable
* @return bool
*/
public function isEnable($isEnable = null)
{
if(is_bool($isEnable)) {
$this->enable = $isEnable;
}

return $this->enable;
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$config = $form->getConfig();
$view->vars['enable'] = $config->getAttribute('enable');

if (!$view->vars['enable']) {
return;
}

if(!isset($view->vars['attr'])) {
$view->vars['attr'] = [];
}
if(!isset($view->vars['attr']['class'])) {
$view->vars['attr']['class'] = '';
}

$view->vars['attr']['class'] .= ' tinymce';
$view->vars['attr']['data-tinymce'] = '' . (self::$id ++);
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->setAttribute('enable', $options['enable']);
if($this->configManager->hasConfig('config')) {
$config = $this->configManager->getConfig('config');
} else {
$config = [];
}

$checkTypes = [
'config_name', 'language', 'selector', 'plugins', 'extended_valid_elements',
'toolbar', 'quickbars_selection_toolbar', 'quickbars_insert_toolbar',
'valid_elements', 'file_picker', 'variables', 'valid_children', 'entity_encoding ',
'content_style',
];

foreach ($checkTypes as $type) {
if(isset($options[$type]) && $options[$type] !== null) {
$config[$type] = $options[$type];
}
}

$this->configManager->setConfig('config', $config);
if (!$options['enable']) {
return;
}
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'config_name' => $this->configManager->getDefaultConfig(),
'language' => null,
'selector' => null,
'plugins' => null,
'toolbar' => null,
'quickbars_selection_toolbar' => null,
'quickbars_insert_toolbar' => null,
'valid_elements' => null,
'valid_children' => null,
'entity_encoding ' => 'raw',
'extended_valid_elements' => null,
'file_picker' => null,
'enable' => $this->enable,
'variables' => null,
'content_style' => '',
])
->setAllowedTypes('config_name', ['string', 'null'])
->setAllowedTypes('language', ['string', 'null'])
->setAllowedTypes('selector', ['string', 'null'])
->setAllowedTypes('plugins', ['string', 'null'])
->setAllowedTypes('toolbar', ['string', 'null'])
->setAllowedTypes('quickbars_selection_toolbar', ['string', 'null'])
->setAllowedTypes('quickbars_insert_toolbar', ['string', 'null'])
->setAllowedTypes('valid_elements', ['string', 'null'])
->setAllowedTypes('valid_children', ['string', 'null'])
->setAllowedTypes('entity_encoding ', ['string'])
->setAllowedTypes('extended_valid_elements', ['string', 'null'])
->setAllowedTypes('file_picker', ['array', 'null'])
->setAllowedTypes('variables', ['array', 'null'])
->setAllowedTypes('enable', 'bool')
;
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return method_exists(AbstractType::class, 'getBlockPrefix') ? TextareaType::class : 'textarea';
}

/**
* @return string
*/
public function getName()
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'tinymce';
}
}
2 changes: 1 addition & 1 deletion Helper/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LocaleHelper
*
* @return string
*/
public static function getLanguage($locale): string
public static function getLanguage(string $locale): string
{
return self::$locales[$locale] ?? $locale;
}
Expand Down
Loading