You are here

public function LinkitDrupalLink::settingsForm in Linkit 8.5

Returns a settings form to configure this CKEditor plugin.

If the plugin's behavior depends on extensive options and/or external data, then the implementing module can choose to provide a separate, global configuration page rather than per-text-editor settings. In that case, this form should provide a link to the separate settings page.

Parameters

array $form: An empty form array to be populated with a configuration form, if any.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the entire filter administration form.

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

Return value

array A render array for the settings form.

Overrides CKEditorPluginConfigurableInterface::settingsForm

File

src/Plugin/CKEditorPlugin/LinkitDrupalLink.php, line 48

Class

LinkitDrupalLink
Adds a settings form to select a Linkit profile on the default link plugin.

Namespace

Drupal\linkit\Plugin\CKEditorPlugin

Code

public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
  $settings = $editor
    ->getSettings();
  $all_profiles = $this->linkitProfileStorage
    ->loadMultiple();
  $options = [];
  foreach ($all_profiles as $profile) {
    $options[$profile
      ->id()] = $profile
      ->label();
  }
  $form['linkit_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Linkit enabled'),
    '#default_value' => isset($settings['plugins']['drupallink']['linkit_enabled']) ? $settings['plugins']['drupallink']['linkit_enabled'] : '',
    '#description' => $this
      ->t('Enable Linkit for this text format.'),
  ];
  $form['linkit_profile'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Linkit profile'),
    '#options' => $options,
    '#default_value' => isset($settings['plugins']['drupallink']['linkit_profile']) ? $settings['plugins']['drupallink']['linkit_profile'] : '',
    '#empty_option' => $this
      ->t('- Select -'),
    '#description' => $this
      ->t('Select the Linkit profile you wish to use with this text format.'),
    '#states' => [
      'invisible' => [
        'input[data-drupal-selector="edit-editor-settings-plugins-drupallink-linkit-enabled"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
    '#element_validate' => [
      [
        $this,
        'validateLinkitProfileSelection',
      ],
    ],
  ];
  return $form;
}