/** * @covers ::getEnabledButtons * @dataProvider providerGetEnabledButtons */ public function testGetEnabledButtons(array $toolbar_rows, array $expected_buttons) { $editor = $this->prophesize(Editor::class); $editor->getSettings()->willReturn(['toolbar' => ['rows' => $toolbar_rows]]); $enabled_buttons = CKEditorPluginManager::getEnabledButtons($editor->reveal()); $this->assertEquals($expected_buttons, $enabled_buttons); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var \Drupal\embed\EmbedButtonInterface $button */ $button = $this->entity; if ($button->isNew()) { // Get a list of all buttons that are provided by all plugins. $all_buttons = array_reduce($this->ckeditorPluginManager->getButtons(), function ($result, $item) { return array_merge($result, array_keys($item)); }, []); // Ensure that button ID is unique. if (in_array($button->id(), $all_buttons)) { $form_state->setErrorByName('id', $this->t('A CKEditor button with ID %id already exists.', ['%id' => $button->id()])); } } // Run embed type plugin validation. if ($plugin = $button->getTypePlugin()) { $plugin_form_state = clone $form_state; $plugin_form_state->setValues($button->getTypeSettings()); $plugin->validateConfigurationForm($form['type_settings'], $plugin_form_state); if ($errors = $plugin_form_state->getErrors()) { foreach ($errors as $name => $error) { $form_state->setErrorByName($name, $error); } } $form_state->setValue('type_settings', $plugin_form_state->getValues()); } }
/** * {@inheritdoc} */ public function getLibraries(EditorEntity $editor) { $libraries = array('ckeditor/drupal.ckeditor'); // Get the required libraries for any enabled plugins. $enabled_plugins = array_keys($this->ckeditorPluginManager->getEnabledPluginFiles($editor)); foreach ($enabled_plugins as $plugin_id) { $plugin = $this->ckeditorPluginManager->createInstance($plugin_id); $additional_libraries = array_diff($plugin->getLibraries($editor), $libraries); $libraries = array_merge($libraries, $additional_libraries); } return $libraries; }
/** * Builds the "contentsCss" configuration part of the CKEditor JS settings. * * @see getJSSettings() * * @param \Drupal\editor\Entity\Editor $editor * A configured text editor object. * @return array * An array containing the "contentsCss" configuration. */ public function buildContentsCssJSSetting(Editor $editor) { $css = array(drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css', drupal_get_path('module', 'system') . '/css/components/align.module.css'); $this->moduleHandler->alter('ckeditor_css', $css, $editor); // Get a list of all enabled plugins' iframe instance CSS files. $plugins_css = array_reduce($this->ckeditorPluginManager->getCssFiles($editor), function ($result, $item) { return array_merge($result, array_values($item)); }, array()); $css = array_merge($css, $plugins_css); $css = array_merge($css, _ckeditor_theme_css()); $css = array_map('file_create_url', $css); $css = array_map('file_url_transform_relative', $css); return array_values($css); }
/** * {@inheritdoc} */ public function getConfig(Editor $editor) { // Reasonable defaults that provide expected basic behavior. $config = array('customConfig' => '', 'pasteFromWordPromptCleanup' => TRUE, 'resize_dir' => 'vertical', 'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'), 'entities' => FALSE, 'disableNativeSpellChecker' => FALSE); // Add the allowedContent setting, which ensures CKEditor only allows tags // and attributes that are allowed by the text format for this text editor. list($config['allowedContent'], $config['disallowedContent']) = $this->generateACFSettings($editor); // Add the format_tags setting, if its button is enabled. $toolbar_buttons = CKEditorPluginManager::getEnabledButtons($editor); if (in_array('Format', $toolbar_buttons)) { $config['format_tags'] = $this->generateFormatTagsSetting($editor); } return $config; }