You are here

public function VideoFilterDialog::getPluginOptions in Video Filter 8

Get plugin embedding options.

File

src/Form/VideoFilterDialog.php, line 184

Class

VideoFilterDialog
Provides Video Filter dialog for text editors.

Namespace

Drupal\video_filter\Form

Code

public function getPluginOptions(array &$form, FormStateInterface $form_state) {
  $response = new AjaxResponse();

  // Video URL.
  $url = $form_state
    ->getValue('url');
  if (!empty($url)) {
    $vf = new VideoFilterCore();
    $plugin = $vf
      ->loadPlugins($url);
    if (!empty($plugin['id'])) {

      // Show embedding options.
      $form['options'][$plugin['id']]['#prefix'] = '';
      $form['options'][$plugin['id']]['#suffix'] = '';

      // Enable button.
      $form['actions']['save_modal']['#attributes'] = [];

      // Enalbe algin options.
      $form['align']['#prefix'] = '';
      $form['align']['#suffix'] = '';

      // Hide Instructions message.
      $form['info']['empty']['#prefix'] = '<div class="visually-hidden">';
      $form['info']['empty']['#suffix'] = '</div>';

      // Hide Not Supported message.
      $form['info']['not-supported']['#prefix'] = '<div class="visually-hidden">';
      $form['info']['not-supported']['#suffix'] = '</div>';
    }
    else {

      // Hide Insert button.
      $form['actions']['save_modal']['#attributes'] = [
        'disabled' => 'true',
      ];

      // Hide Instructions message.
      $form['info']['empty']['#prefix'] = '<div class="visually-hidden">';
      $form['info']['empty']['#suffix'] = '</div>';

      // Show Not Supported message.
      $form['info']['not-supported']['#prefix'] = '';
      $form['info']['not-supported']['#suffix'] = '';
    }
  }
  $response
    ->addCommand(new HtmlCommand('#video-filter-dialog-form', $form));
  return $response;
}