Example #1
0
 /**
  * {@inheritdoc}
  */
 function isEnabled(Editor $editor)
 {
     if (!$editor->hasAssociatedFilterFormat()) {
         return FALSE;
     }
     // Automatically enable this plugin if the text format associated with this
     // text editor uses the filter_align or filter_caption filter and the
     // DrupalImage button is enabled.
     $format = $editor->getFilterFormat();
     if ($format->filters('filter_align')->status || $format->filters('filter_caption')->status) {
         $enabled = FALSE;
         $settings = $editor->getSettings();
         foreach ($settings['toolbar']['rows'] as $row) {
             foreach ($row as $group) {
                 foreach ($group['items'] as $button) {
                     if ($button === 'DrupalImage') {
                         $enabled = TRUE;
                     }
                 }
             }
         }
         return $enabled;
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $editor_settings = $editor->getSettings();
     $plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
     $settings = $plugin_settings ?: [];
     $form['defaults'] = ['#title' => $this->t('Default Settings'), '#type' => 'fieldset', '#tree' => TRUE, 'children' => Video::mockInstance($settings)->settingsForm([], new FormState())];
     return $form;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 function getJSSettings(EditorEntity $editor)
 {
     $js_settings = array();
     $settings = $editor->getSettings();
     if ($settings['ponies too']) {
         $js_settings['ponyModeEnabled'] = TRUE;
     }
     return $js_settings;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getJSSettings(EditorEntity $editor)
 {
     $js_settings = array();
     $settings = $editor->getSettings();
     if ($settings['stumpy_arms']) {
         $js_settings['doMyArmsLookStumpy'] = TRUE;
     }
     return $js_settings;
 }
 /**
  * Implements \Drupal\ckeditor\Plugin\CKEditorPluginConfigurableInterface::settingsForm().
  */
 function settingsForm(array $form, array &$form_state, Editor $editor)
 {
     // Defaults.
     $config = array('ultra_llama_mode' => FALSE);
     $settings = $editor->getSettings();
     if (isset($settings['plugins']['llama_contextual_and_button'])) {
         $config = $settings['plugins']['llama_contextual_and_button'];
     }
     $form['ultra_llama_mode'] = array('#title' => t('Ultra llama mode'), '#type' => 'checkbox', '#default_value' => $config['ultra_llama_mode']);
     return $form;
 }
Example #6
0
 /**
  * Implements \Drupal\ckeditor\Plugin\CKEditorPluginConfigurableInterface::settingsForm().
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     // Defaults.
     $config = array('styles' => '');
     $settings = $editor->getSettings();
     if (isset($settings['plugins']['stylescombo'])) {
         $config = $settings['plugins']['stylescombo'];
     }
     $form['styles'] = array('#title' => t('Styles'), '#title_display' => 'invisible', '#type' => 'textarea', '#default_value' => $config['styles'], '#description' => t('A list of classes that will be provided in the "Styles" dropdown. Enter one class on each line in the format: element.class|Label. Example: h1.title|Title.<br />These styles should be available in your theme\'s CSS file.'), '#attached' => array('library' => array('ckeditor/drupal.ckeditor.stylescombo.admin')), '#element_validate' => array(array($this, 'validateStylesValue')));
     return $form;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 function isEnabled(Editor $editor)
 {
     // Automatically enable this plugin if the Underline button is enabled.
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row) {
         foreach ($row as $group) {
             if (in_array('Strike', $group['items'])) {
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $styles = $this->getStyles();
     $config = \Drupal::config('codesnippet.settings');
     $default_style = $config->get('style');
     $languages = $config->get('languages');
     asort($languages);
     $form['#attached']['library'][] = 'codesnippet/codesnippet.admin';
     $form['highlight_style'] = array('#type' => 'select', '#title' => 'highlight.js Style', '#description' => $this->t('Select a style to apply to all highlighted code snippets. You can preview the styles at @link.', array('@link' => \Drupal::l('https://highlightjs.org/static/demo', Url::fromUri('https://highlightjs.org/static/demo/')))), '#options' => $styles, '#default_value' => !empty($settings['plugins']['codesnippet']['highlight_style']) ? $settings['plugins']['codesnippet']['highlight_style'] : $default_style);
     $form['highlight_languages'] = array('#type' => 'checkboxes', '#title' => 'Supported Languages', '#options' => $languages, '#description' => t('Enter languages you want to have as options in the editor dialog. To add a language not in this list, please see the README.txt of this module.'), '#default_value' => $settings['plugins']['codesnippet']['highlight_languages']);
     return $form;
 }
 /**
  * Retrieves enabled plugins' files, keyed by plugin ID.
  *
  * For CKEditor plugins that implement:
  *  - CKEditorPluginButtonsInterface, not CKEditorPluginContextualInterface,
  *     a plugin is enabled if at least one of its buttons is in the toolbar;
  *  - CKEditorPluginContextualInterface, not CKEditorPluginButtonsInterface,
  *     a plugin is enabled if its isEnabled() method returns TRUE
  *  - both of these interfaces, a plugin is enabled if either is the case.
  *
  * Internal plugins (those that are part of the bundled build of CKEditor) are
  * excluded by default, since they are loaded implicitly. If you need to know
  * even implicitly loaded (i.e. internal) plugins, then set the optional
  * second parameter.
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  * @param bool $include_internal_plugins
  *   Defaults to FALSE. When set to TRUE, plugins whose isInternal() method
  *   returns TRUE will also be included.
  * @return array
  *   A list of the enabled CKEditor plugins, with the plugin IDs as keys and
  *   the Drupal root-relative plugin files as values.
  *   For internal plugins, the value is NULL.
  */
 public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE)
 {
     $plugins = array_keys($this->getDefinitions());
     // Flatten each row.
     $toolbar_rows = array();
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row_number => $row) {
         $toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
             return array_merge($result, $button_group['items']);
         }, array());
     }
     $toolbar_buttons = array_unique(NestedArray::mergeDeepArray($toolbar_rows));
     $enabled_plugins = array();
     $additional_plugins = array();
     foreach ($plugins as $plugin_id) {
         $plugin = $this->createInstance($plugin_id);
         if (!$include_internal_plugins && $plugin->isInternal()) {
             continue;
         }
         $enabled = FALSE;
         // Enable this plugin if it provides a button that has been enabled.
         if ($plugin instanceof CKEditorPluginButtonsInterface) {
             $plugin_buttons = array_keys($plugin->getButtons());
             $enabled = count(array_intersect($toolbar_buttons, $plugin_buttons)) > 0;
         }
         // Otherwise enable this plugin if it declares itself as enabled.
         if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
             $enabled = $plugin->isEnabled($editor);
         }
         if ($enabled) {
             $enabled_plugins[$plugin_id] = $plugin->isInternal() ? NULL : $plugin->getFile();
             // Check if this plugin has dependencies that also need to be enabled.
             $additional_plugins = array_merge($additional_plugins, array_diff($plugin->getDependencies($editor), $additional_plugins));
         }
     }
     // Add the list of dependent plugins.
     foreach ($additional_plugins as $plugin_id) {
         $plugin = $this->createInstance($plugin_id);
         $enabled_plugins[$plugin_id] = $plugin->isInternal() ? NULL : $plugin->getFile();
     }
     // Always return plugins in the same order.
     asort($enabled_plugins);
     return $enabled_plugins;
 }
 /**
  * Returns the selected Medium Editor id for an account from editor settings.
  */
 public static function getMediumId(Editor $editor, AccountInterface $account)
 {
     $settings = $editor->getSettings();
     if (!empty($settings['roles_editors'])) {
         // Filter roles in two steps. May avoid a db hit by filter_get_roles_by_format().
         if ($roles_editors = array_intersect_key($settings['roles_editors'], array_flip($account->getRoles()))) {
             if ($roles_editors = array_intersect_key($roles_editors, filter_get_roles_by_format($editor->getFilterFormat()))) {
                 return reset($roles_editors);
             }
         }
     }
     return $settings['default_editor'];
 }
Example #11
0
 /**
  * Gets the enabled toolbar buttons in the given text editor instance.
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  *
  * @return string[]
  *   A list of the toolbar buttons enabled in the given text editor instance.
  */
 public static function getEnabledButtons(Editor $editor)
 {
     $toolbar_rows = [];
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row_number => $row) {
         $toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
             return array_merge($result, $button_group['items']);
         }, []);
     }
     return array_unique(NestedArray::mergeDeepArray($toolbar_rows));
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     // Defaults.
     $config = ['language_list' => 'un'];
     $settings = $editor->getSettings();
     if (isset($settings['plugins']['language'])) {
         $config = $settings['plugins']['language'];
     }
     $predefined_languages = LanguageManager::getStandardLanguageList();
     $form['language_list'] = array('#title' => $this->t('Language list'), '#title_display' => 'invisible', '#type' => 'select', '#options' => ['un' => $this->t("United Nations' official languages"), 'all' => $this->t('All @count languages', ['@count' => count($predefined_languages)])], '#default_value' => $config['language_list'], '#description' => $this->t('The list of languages to show in the language dropdown. The basic list will only show the <a href=":url">six official languages of the UN</a>. The extended list will show all @count languages that are available in Drupal.', [':url' => Url::fromUri('http://www.un.org/en/aboutun/languages.shtml/')->toString(), '@count' => count($predefined_languages)]), '#attached' => ['library' => ['ckeditor/drupal.ckeditor.language.admin']]);
     return $form;
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $form['status'] = array('#type' => 'radios', '#title' => $this->t('Enable auto embed'), '#options' => array('' => $this->t('Disabled'), 'embed' => t('Media Embed'), 'embedsemantic' => t('Semantic Media Embed')), '#default_value' => !empty($settings['plugins']['autoembed']['status']) ? $settings['plugins']['autoembed']['status'] : '', '#description' => $this->t('When enabled to a Media embed plugin, media resource URLs pasted into the editing area are turned into an embed resource using the selected plugin.'));
     return $form;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $form['settings_info'] = array('#markup' => $this->t('Settings for the Media Embed and Semantic Media Embed plugins are located on the @link.', array('@link' => \Drupal::service('ckeditor_media_embed')->getSettingsLink())));
     return $form;
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function isEnabled(Editor $editor)
 {
     $enabled = FALSE;
     if (!$editor->hasAssociatedFilterFormat()) {
         return $enabled;
     }
     $editor_settings = $editor->getSettings();
     $plugin_settings = !empty($editor_settings['plugins']['embridgeimage']['embridge_image_upload']) ? $editor_settings['plugins']['embridgeimage']['embridge_image_upload'] : [];
     if (!empty($plugin_settings['enabled']) && $plugin_settings['enabled']) {
         $enabled = TRUE;
     }
     return $enabled;
 }
Example #16
0
  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
    $settings = $editor->getSettings();

    $all_profiles = $this->linkitProfileStorage->loadMultiple();

    $options = array();
    foreach ($all_profiles as $profile) {
      $options[$profile->id()] = $profile->label();
    }

    $form['linkit_profile'] = array(
      '#type' => 'select',
      '#title' => t('Select a linkit profile'),
      '#options' => $options,
      '#default_value' => isset($settings['plugins']['linkit']) ? $settings['plugins']['linkit'] : '',
      '#empty_option' => $this->t('- Select profile -'),
      '#description' => $this->t('Select the linkit profile you wish to use with this text format.'),
      '#element_validate' => array(
        array($this, 'validateLinkitProfileSelection'),
      ),
    );

    return $form;
  }
 /**
  * Builds the "toolbar" 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 "toolbar" configuration.
  */
 public function buildToolbarJSSetting(EditorEntity $editor)
 {
     $toolbar = array();
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row) {
         foreach ($row as $group) {
             $toolbar[] = $group;
         }
         $toolbar[] = '/';
     }
     return $toolbar;
 }