/** * {@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; }
/** * {@inheritdoc} */ public static function defaultSettings() { return Thumbnail::defaultSettings() + Video::defaultSettings() + ['modal_max_width' => '854']; }
/** * Get the values from the form and provider required for the client. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state from the dialog submission. * @param \Drupal\video_embed_field\ProviderPluginInterface $provider * The provider loaded from the user input. * * @return array * An array of values sent to the client for use in the WYSIWYG. */ protected function getClientValues(FormStateInterface $form_state, ProviderPluginInterface $provider) { // All settings from the field formatter exist in the form and are relevant // for the rendering of the video. $video_formatter_settings = Video::defaultSettings(); foreach ($video_formatter_settings as $key => $default) { $video_formatter_settings[$key] = $form_state->getValue($key); } $provider->downloadThumbnail(); $thumbnail_preview = ImageStyle::load('video_embed_wysiwyg_preview')->buildUrl($provider->getLocalThumbnailUri()); $thumbnail_preview_parts = parse_url($thumbnail_preview); return ['preview_thumbnail' => $thumbnail_preview_parts['path'] . (!empty($thumbnail_preview_parts['query']) ? '?' : '') . $thumbnail_preview_parts['query'], 'video_url' => $form_state->getValue('video_url'), 'settings' => $video_formatter_settings, 'settings_summary' => Video::mockInstance($video_formatter_settings)->settingsSummary()]; }
/** * {@inheritdoc} */ public static function defaultSettings() { return Thumbnail::defaultSettings() + Video::defaultSettings(); }
/** * Get the values from the form and provider required for the client. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state from the dialog submission. * @param \Drupal\video_embed_field\ProviderPluginInterface $provider * The provider loaded from the user input. * * @return array * An array of values sent to the client for use in the WYSIWYG. */ protected function getClientValues(FormStateInterface $form_state, $provider) { // @todo Render the thumbnail to download it from the remote. Consider // making the download method public. https://www.drupal.org/node/2687077 $provider->renderThumbnail(FALSE, FALSE); // All settings from the field formatter exist in the form and are relevant // for the rendering of the video. $video_formatter_settings = Video::defaultSettings(); foreach ($video_formatter_settings as $key => $default) { $video_formatter_settings[$key] = $form_state->getValue($key); } return ['preview_thumbnail' => ImageStyle::load('video_embed_wysiwyg_preview')->buildUrl($provider->getLocalThumbnailUri()), 'video_url' => $form_state->getValue('video_url'), 'settings' => $video_formatter_settings, 'settings_summary' => $this->getVideoFormatterInstance($video_formatter_settings)->settingsSummary()]; }
/** * Check if the given settings are valid. * * @param array $settings * Settings to validate. * * @return bool * If the required settings are present. */ protected function validSettings($settings) { foreach (Video::defaultSettings() as $setting => $default) { if (!isset($settings[$setting])) { return FALSE; } } return TRUE; }