public function VideoFilterDialog::buildForm in Video Filter 8
Parameters
\Drupal\filter\Entity\FilterFormat $filter_format: The filter format for which this dialog corresponds.
Overrides FormInterface::buildForm
File
- src/
Form/ VideoFilterDialog.php, line 42
Class
- VideoFilterDialog
- Provides Video Filter dialog for text editors.
Namespace
Drupal\video_filter\FormCode
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) {
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
$form['#prefix'] = '<div id="video-filter-dialog-form">';
$form['#suffix'] = '</div>';
$form['url'] = [
'#title' => $this
->t('Video URL'),
'#type' => 'textfield',
'#maxlength' => 2048,
'#ajax' => [
'callback' => '::getPluginOptions',
'event' => 'change',
],
];
$form['options'] = [];
$vf = new VideoFilterCore();
$plugins = $vf
->loadPlugins();
foreach ($plugins['plugins'] as $id => $plugin_info) {
if (!empty($plugin_info['options'])) {
$form['options'][$id] = [
'#type' => 'details',
'#title' => $this
->t('Options'),
'#open' => TRUE,
'#prefix' => '<div class="visually-hidden">',
'#suffix' => '</div>',
];
$form['options'][$id]['options'] = $plugin_info['options'];
}
}
$form['info']['empty'] = [
'#markup' => $this
->t('Please copy URL from browser and paste it into Video URL field. Available embedding options will be displayed under this field.'),
'#prefix' => '<div class="info-empty">',
'#suffix' => '</div>',
];
$form['info']['not-supported'] = [
'#markup' => $this
->t('The URL you provided is not supported. Please contact your developer to extend this module.'),
'#prefix' => '<div class="visually-hidden">',
'#suffix' => '</div>',
];
$form['align'] = [
'#title' => $this
->t('Align (optional)'),
'#type' => 'select',
'#default_value' => 'none',
'#options' => [
'none' => $this
->t('None'),
'left' => $this
->t('Left'),
'right' => $this
->t('Right'),
'center' => $this
->t('Center'),
],
'#prefix' => '<div class="visually-hidden">',
'#suffix' => '</div>',
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save_modal'] = [
'#type' => 'submit',
'#value' => $this
->t('Insert'),
// No regular submit-handler. This form only works via JavaScript.
'#submit' => [],
'#ajax' => [
'callback' => '::submitForm',
'event' => 'click',
],
'#attributes' => [
'disabled' => 'true',
],
];
// This is the element where we put generated code
// By doing this we can generate [video:url]
// in PHP instead of generating it in CKEditor JS plugin.
$form['attributes']['code'] = [
'#title' => $this
->t('Video Filter'),
'#type' => 'textfield',
'#prefix' => '<div class="visually-hidden">',
'#suffix' => '</div>',
];
return $form;
}