vendor/friendsofsymfony/ckeditor-bundle/src/Model/ToolbarManager.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSCKEditor Bundle.
  4.  *
  5.  * (c) 2018 - present  Friends of Symfony
  6.  * (c) 2009 - 2017     Eric GELOEN <geloen.eric@gmail.com>
  7.  *
  8.  * For the full copyright and license information, please read the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace FOS\CKEditorBundle\Model;
  12. use FOS\CKEditorBundle\Exception\ToolbarManagerException;
  13. @trigger_error(
  14.     'The '.__NAMESPACE__.'ToolbarManager is deprecated since 1.x '.
  15.     'and will be removed with the 2.0 release.',
  16.     E_USER_DEPRECATED
  17. );
  18. /**
  19.  * @author GeLo <geloen.eric@gmail.com>
  20.  */
  21. class ToolbarManager implements ToolbarManagerInterface
  22. {
  23.     /**
  24.      * @var array
  25.      */
  26.     private $items = [
  27.         'basic.about' => ['About'],
  28.         'basic.basic_styles' => ['Bold''Italic'],
  29.         'basic.links' => ['Link''Unlink'],
  30.         'basic.paragraph' => ['NumberedList''BulletedList''-''Outdent''Indent'],
  31.         'standard.about' => ['Styles''Format''About'],
  32.         'standard.basic_styles' => ['Bold''Italic''Strike''-''RemoveFormat'],
  33.         'standard.clipboard' => ['Cut''Copy''Paste''PasteText''PasteFromWord''-''Undo''Redo'],
  34.         'standard.document' => ['Source'],
  35.         'standard.editing' => ['Scayt'],
  36.         'standard.links' => ['Link''Unlink''Anchor'],
  37.         'standard.insert' => ['Image''Table''HorizontalRule''SpecialChar'],
  38.         'standard.paragraph' => ['NumberedList''BulletedList''-''Outdent''Indent''-''Blockquote'],
  39.         'standard.tools' => ['Maximize'],
  40.         'full.about' => ['About'],
  41.         'full.basic_styles' => [
  42.             'Bold',
  43.             'Italic',
  44.             'Underline',
  45.             'Strike',
  46.             'Subscript',
  47.             'Superscript',
  48.             '-',
  49.             'RemoveFormat',
  50.         ],
  51.         'full.clipboard' => ['Cut''Copy''Paste''PasteText''PasteFromWord''-''Undo''Redo'],
  52.         'full.colors' => ['TextColor''BGColor'],
  53.         'full.document' => ['Source''-''NewPage''Preview''Print''-''Templates'],
  54.         'full.editing' => ['Find''Replace''-''SelectAll''-''Scayt'],
  55.         'full.forms' => [
  56.             'Form',
  57.             'Checkbox',
  58.             'Radio',
  59.             'TextField',
  60.             'Textarea',
  61.             'SelectField',
  62.             'Button',
  63.             'ImageButton',
  64.             'HiddenField',
  65.         ],
  66.         'full.insert' => ['Image''Flash''Table''HorizontalRule''SpecialChar''Smiley''PageBreak''Iframe'],
  67.         'full.links' => ['Link''Unlink''Anchor'],
  68.         'full.paragraph' => [
  69.             'NumberedList',
  70.             'BulletedList',
  71.             '-',
  72.             'Outdent',
  73.             'Indent',
  74.             '-',
  75.             'Blockquote',
  76.             'CreateDiv',
  77.             '-',
  78.             'JustifyLeft',
  79.             'JustifyCenter',
  80.             'JustifyRight',
  81.             'JustifyBlock',
  82.             '-',
  83.             'BidiLtr',
  84.             'BidiRtl',
  85.         ],
  86.         'full.styles' => ['Styles''Format''Font''FontSize''TextColor''BGColor'],
  87.         'full.tools' => ['Maximize''ShowBlocks'],
  88.     ];
  89.     /**
  90.      * @var array
  91.      */
  92.     private $toolbars = [
  93.         'basic' => [
  94.             '@basic.basic_styles',
  95.             '@basic.paragraph',
  96.             '@basic.links',
  97.             '@basic.about',
  98.         ],
  99.         'standard' => [
  100.             '@standard.clipboard',
  101.             '@standard.editing',
  102.             '@standard.links',
  103.             '@standard.insert',
  104.             '@standard.tools',
  105.             '@standard.document',
  106.             '/',
  107.             '@standard.basic_styles',
  108.             '@standard.paragraph',
  109.             '@standard.about',
  110.         ],
  111.         'full' => [
  112.             '@full.document',
  113.             '@full.clipboard',
  114.             '@full.editing',
  115.             '@full.forms',
  116.             '/',
  117.             '@full.basic_styles',
  118.             '@full.paragraph',
  119.             '@full.links',
  120.             '@full.insert',
  121.             '/',
  122.             '@full.styles',
  123.             '@full.colors',
  124.             '@full.tools',
  125.             '@full.about',
  126.         ],
  127.     ];
  128.     /**
  129.      * @param array $items
  130.      * @param array $toolbars
  131.      */
  132.     public function __construct(array $items = [], array $toolbars = [])
  133.     {
  134.         $this->setItems($items);
  135.         $this->setToolbars($toolbars);
  136.     }
  137.     /**
  138.      * {@inheritdoc}
  139.      */
  140.     public function hasItems()
  141.     {
  142.         return !empty($this->items);
  143.     }
  144.     /**
  145.      * {@inheritdoc}
  146.      */
  147.     public function getItems()
  148.     {
  149.         return $this->items;
  150.     }
  151.     /**
  152.      * {@inheritdoc}
  153.      */
  154.     public function setItems(array $items)
  155.     {
  156.         foreach ($items as $name => $item) {
  157.             $this->setItem($name$item);
  158.         }
  159.     }
  160.     /**
  161.      * {@inheritdoc}
  162.      */
  163.     public function hasItem($name)
  164.     {
  165.         return isset($this->items[$name]);
  166.     }
  167.     /**
  168.      * {@inheritdoc}
  169.      */
  170.     public function getItem($name)
  171.     {
  172.         if (!$this->hasItem($name)) {
  173.             throw ToolbarManagerException::itemDoesNotExist($name);
  174.         }
  175.         return $this->items[$name];
  176.     }
  177.     /**
  178.      * {@inheritdoc}
  179.      */
  180.     public function setItem($name, array $item)
  181.     {
  182.         $this->items[$name] = $item;
  183.     }
  184.     /**
  185.      * {@inheritdoc}
  186.      */
  187.     public function hasToolbars()
  188.     {
  189.         return !empty($this->toolbars);
  190.     }
  191.     /**
  192.      * {@inheritdoc}
  193.      */
  194.     public function getToolbars()
  195.     {
  196.         return $this->toolbars;
  197.     }
  198.     /**
  199.      * {@inheritdoc}
  200.      */
  201.     public function setToolbars(array $toolbars)
  202.     {
  203.         foreach ($toolbars as $name => $toolbar) {
  204.             $this->setToolbar($name$toolbar);
  205.         }
  206.     }
  207.     /**
  208.      * {@inheritdoc}
  209.      */
  210.     public function hasToolbar($name)
  211.     {
  212.         return isset($this->toolbars[$name]);
  213.     }
  214.     /**
  215.      * {@inheritdoc}
  216.      */
  217.     public function getToolbar($name)
  218.     {
  219.         if (!$this->hasToolbar($name)) {
  220.             throw ToolbarManagerException::toolbarDoesNotExist($name);
  221.         }
  222.         return $this->toolbars[$name];
  223.     }
  224.     /**
  225.      * {@inheritdoc}
  226.      */
  227.     public function setToolbar($name, array $toolbar)
  228.     {
  229.         $this->toolbars[$name] = $toolbar;
  230.     }
  231.     /**
  232.      * {@inheritdoc}
  233.      */
  234.     public function resolveToolbar($name)
  235.     {
  236.         $toolbars = [];
  237.         foreach ($this->getToolbar($name) as $name => $item) {
  238.             $toolbars[] = is_string($item) && '@' === substr($item01)
  239.                 ? $this->getItem(substr($item1))
  240.                 : $item;
  241.         }
  242.         return $toolbars;
  243.     }
  244. }