Skip to content

Commit

Permalink
Merge pull request #240 from stfalcon/fix-2.x
Browse files Browse the repository at this point in the history
Some updates and improvements
  • Loading branch information
fre5h committed Dec 9, 2019
2 parents 3455d81 + b085588 commit e72bc3d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 64 deletions.
42 changes: 21 additions & 21 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* TinymceBundle configuration structure.
* Configuration.
*/
class Configuration implements ConfigurationInterface
{
Expand All @@ -15,14 +15,14 @@ class Configuration implements ConfigurationInterface
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$defaults = $this->getTinymceDefaults();

$treeBuilder = new TreeBuilder('stfalcon_tinymce');
$treeBuilder = new TreeBuilder();

return $treeBuilder
->getRootNode()
->root('stfalcon_tinymce', 'array')
->children()
// Include jQuery (true) library or not (false)
->booleanNode('include_jquery')->defaultFalse()->end()
Expand Down Expand Up @@ -79,23 +79,23 @@ public function getConfigTreeBuilder()
*
* @return array
*/
private function getTinymceDefaults()
private function getTinymceDefaults(): array
{
return array(
'advanced' => array(
"theme" => "modern",
"plugins" => array(
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor",
),
"toolbar1" => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify
| bullist numlist outdent indent | link image",
"toolbar2" => "print preview media | forecolor backcolor emoticons",
"image_advtab" => true,
),
'simple' => array(),
);
return [
'advanced' => [
'theme' => 'modern',
'plugins' => [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor',
],
'toolbar1' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify
| bullist numlist outdent indent | link image',
'toolbar2' => 'print preview media | forecolor backcolor emoticons',
'image_advtab' => true,
],
'simple' => [],
];
}
}
16 changes: 8 additions & 8 deletions DependencyInjection/StfalconTinymceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* StfalconTinymceExtension
* StfalconTinymceExtension.
*/
class StfalconTinymceExtension extends Extension
{
/**
* Loads the StfalconTinymce configuration.
* Loads the StfalconTinymceBundle configuration.
*
* @param array $configs An array of configuration values
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
// Get default configuration of the bundle
$config = $this->processConfiguration(new Configuration(), $configs);

if (empty($config['theme'])) {
$config['theme'] = array(
'simple' => array(),
);
$config['theme'] = [
'simple' => [],
];
} else {
foreach ($config['theme'] as &$bundleTheme) {
// Quick fix for the removed obsolete themes
if (isset($bundleTheme['theme']) && in_array($bundleTheme['theme'], array('advanced', 'simple'))) {
if (isset($bundleTheme['theme']) && \in_array($bundleTheme['theme'], ['advanced', 'simple'], true)) {
$bundleTheme['theme'] = 'modern';
}
unset($bundleTheme);
Expand All @@ -51,7 +51,7 @@ public function load(array $configs, ContainerBuilder $container)
*
* @return string The alias
*/
public function getAlias()
public function getAlias(): string
{
return 'stfalcon_tinymce';
}
Expand Down
14 changes: 5 additions & 9 deletions Helper/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Stfalcon\Bundle\TinymceBundle\Helper;

/**
* Class LocaleHelper
*
* @package Stfalcon\Bundle\TinymceBundle\Helper
* LocaleHelper.
*/
class LocaleHelper
{
static private $locales = array(
private static $locales = [
'bn' => 'bn_BD',
'bg' => 'bg_BG',
'cn' => 'zh_CN',
Expand All @@ -21,17 +19,15 @@ class LocaleHelper
'tr' => 'tr_TR',
'tw' => 'zh_TW',
'uk' => 'uk_UA',
);
];

/**
* @param string $locale
*
* @return string
*/
public static function getLanguage($locale)
public static function getLanguage($locale): string
{
return isset(self::$locales[$locale])
? self::$locales[$locale]
: $locale;
return self::$locales[$locale] ?? $locale;
}
}
50 changes: 25 additions & 25 deletions Twig/Extension/StfalconTinymceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class StfalconTinymceExtension extends \Twig_Extension
private $packages;

/**
* Initialize tinymce helper
*
* @param ContainerInterface $container
* @param Packages $packages
*/
public function __construct(ContainerInterface $container, Packages $packages)
{
Expand All @@ -43,8 +42,6 @@ public function __construct(ContainerInterface $container, Packages $packages)
}

/**
* Gets a service.
*
* @param string $id The service identifier
*
* @return object The associated service
Expand Down Expand Up @@ -73,13 +70,13 @@ public function getParameter($name)
*/
public function getFunctions()
{
return array(
return [
'tinymce_init' => new \Twig_SimpleFunction(
'tinymce_init',
array($this, 'tinymceInit'),
array('is_safe' => array('html'))
[$this, 'tinymceInit'],
['is_safe' => ['html']]
),
);
];
}

/**
Expand All @@ -89,7 +86,7 @@ public function getFunctions()
*
* @return string
*/
public function tinymceInit($options = array())
public function tinymceInit($options = []): string
{
$config = $this->getParameter('stfalcon_tinymce.config');
$config = array_merge_recursive($config, $options);
Expand Down Expand Up @@ -159,7 +156,7 @@ public function tinymceInit($options = array())
if (isset($themeOptions['content_css'])) {
// As there may be multiple CSS Files specified we need to parse each of them individually
$cssFiles = $themeOptions['content_css'];
if (!is_array($themeOptions['content_css'])) {
if (!\is_array($themeOptions['content_css'])) {
$cssFiles = explode(',', $themeOptions['content_css']);
}

Expand All @@ -173,35 +170,38 @@ public function tinymceInit($options = array())
}
}

$tinymceConfiguration = preg_replace(
array(
$tinymceConfiguration = \preg_replace(
[
'/"file_browser_callback":"([^"]+)"\s*/',
'/"file_picker_callback":"([^"]+)"\s*/',
'/"paste_preprocess":"([^"]+)"\s*/',
),
array(
],
[
'file_browser_callback:$1',
'file_picker_callback:$1',
'"paste_preprocess":$1',
),
json_encode($config)
],
\json_encode($config)
);

return $this->getService('twig')->render('@StfalconTinymce/Script/init.html.twig', array(
'tinymce_config' => $tinymceConfiguration,
'include_jquery' => $config['include_jquery'],
'tinymce_jquery' => $config['tinymce_jquery'],
'asset_package_name' => $assetPackageName,
'base_url' => $this->baseUrl,
));
return $this->getService('twig')->render(
'@StfalconTinymce/Script/init.html.twig',
[
'tinymce_config' => $tinymceConfiguration,
'include_jquery' => $config['include_jquery'],
'tinymce_jquery' => $config['tinymce_jquery'],
'asset_package_name' => $assetPackageName,
'base_url' => $this->baseUrl,
]
);
}

/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
public function getName(): string
{
return 'stfalcon_tinymce';
}
Expand All @@ -213,7 +213,7 @@ public function getName()
*
* @return string
*/
protected function getAssetsUrl($inputUrl)
protected function getAssetsUrl(string $inputUrl): string
{
$assets = $this->packages;

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require": {
"php": "^7.1.3",
"symfony/framework-bundle": "^3.4||^4.0||^5.0"
"symfony/framework-bundle": "^3.4 || ^4.0"
},
"autoload": {
"psr-0": {
Expand Down

0 comments on commit e72bc3d

Please sign in to comment.