You are here

class YoutubeSettingsForm in YouTube Field 8

Configure Youtube settings for this site.

Hierarchy

Expanded class hierarchy of YoutubeSettingsForm

1 string reference to 'YoutubeSettingsForm'
youtube.routing.yml in ./youtube.routing.yml
youtube.routing.yml

File

src/Form/YoutubeSettingsForm.php, line 11

Namespace

Drupal\youtube\Form
View source
class YoutubeSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'youtube_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'youtube.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->configFactory
      ->get('youtube.settings');
    $form['text'] = [
      '#type' => 'markup',
      '#markup' => '<p>' . $this
        ->t('The following settings will be used as default values on all YouTube video fields.  Many of these settings can be overridden on a per-field basis.') . '</p>',
    ];
    $form['youtube_global'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Video parameters'),
    ];
    $form['youtube_global']['youtube_suggest'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Show suggested videos from any channel - as opposed to only the same channel - when playback ends (rel).'),
      '#default_value' => $config
        ->get('youtube_suggest'),
    ];
    $form['youtube_global']['youtube_modestbranding'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Do not show YouTube logo on video player control bar (modestbranding).'),
      '#default_value' => $config
        ->get('youtube_modestbranding'),
    ];
    $form['youtube_global']['youtube_theme'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use a light colored control bar for video player controls (theme).'),
      '#default_value' => $config
        ->get('youtube_theme'),
    ];
    $form['youtube_global']['youtube_color'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use a white colored video progress bar (color).'),
      '#default_value' => $config
        ->get('youtube_color'),
      '#description' => $this
        ->t('Note: the modestbranding parameter will be ignored when this is in use.'),
    ];
    $form['youtube_global']['youtube_enablejsapi'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable use of the IFrame API (enablejsapi, origin).'),
      '#default_value' => $config
        ->get('youtube_enablejsapi'),
      '#description' => $this
        ->t('For more information on the IFrame API and how to use it, see the <a href="@api_reference">IFrame API documentation</a>.', [
        '@api_reference' => 'https://developers.google.com/youtube/iframe_api_reference',
      ]),
    ];
    $form['youtube_global']['youtube_wmode'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Fix overlay problem on IE8 and lower'),
      '#default_value' => $config
        ->get('youtube_wmode'),
      '#description' => $this
        ->t("Checking this will fix the issue of a YouTube video showing above a modal window (including Drupal's Overlay). This is needed if you have Overlay users in IE or have modal windows throughout your site."),
    ];
    $form['youtube_global']['youtube_override'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Allow users to override parameters.'),
      '#default_value' => $config
        ->get('youtube_override', FALSE),
      '#description' => $this
        ->t('This will allow users to pass parameter values into the YouTube URL provided in the field input. For example, adding "&start=30" to the end of the URL would start the embedded video at the 30 second mark. This may have unintended side effects if parameter values are ever passed by accident.'),
    ];
    $form['youtube_thumbs'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Thumbnails'),
    ];
    $form['youtube_thumbs']['youtube_thumb_dir'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('YouTube thumbnail directory'),
      '#field_prefix' => 'public://',
      '#field_suffix' => '/thumbnail.jpg',
      '#description' => $this
        ->t('Location, within the files directory, where you would like the YouTube thumbnails stored.'),
      '#default_value' => $config
        ->get('youtube_thumb_dir'),
    ];
    $form['youtube_thumbs']['youtube_thumb_hires'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Save higher resolution thumbnail images'),
      '#description' => $this
        ->t('This will save thumbnails larger than the default size, 480x360, to the thumbnails directory specified above.'),
      '#default_value' => $config
        ->get('youtube_thumb_hires'),
    ];
    $form['youtube_thumbs']['youtube_thumb_token_image_style'] = [
      '#type' => 'select',
      '#options' => image_style_options(TRUE),
      '#title' => $this
        ->t('Default token image style'),
      '#description' => $this
        ->t('Default image style for the output of a youtube_image_url token.'),
      '#default_value' => $config
        ->get('youtube_thumb_token_image_style'),
    ];
    $form['youtube_thumbs']['youtube_thumb_delete_all'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Refresh existing thumbnail image files'),
      '#submit' => [
        'youtube_thumb_delete_all',
      ],
    ];
    $form['youtube_privacy'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable privacy-enhanced mode'),
      '#default_value' => $config
        ->get('youtube_privacy'),
      '#description' => $this
        ->t('Checking this box will prevent YouTube from setting cookies in your site visitors browser.'),
    ];
    $form['youtube_player_class'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('YouTube player class'),
      '#default_value' => $config
        ->get('youtube_player_class'),
      '#description' => $this
        ->t('The iframe of every player will be given this class. They will also be given IDs based off of this value.'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $this->configFactory
      ->getEditable('youtube.settings')
      ->set('youtube_suggest', $values['youtube_suggest'])
      ->set('youtube_modestbranding', $values['youtube_modestbranding'])
      ->set('youtube_theme', $values['youtube_theme'])
      ->set('youtube_color', $values['youtube_color'])
      ->set('youtube_enablejsapi', $values['youtube_enablejsapi'])
      ->set('youtube_privacy', $values['youtube_privacy'])
      ->set('youtube_wmode', $values['youtube_wmode'])
      ->set('youtube_override', $values['youtube_override'])
      ->set('youtube_player_class', $values['youtube_player_class'])
      ->set('youtube_thumb_dir', $values['youtube_thumb_dir'])
      ->set('youtube_thumb_hires', $values['youtube_thumb_hires'])
      ->set('youtube_thumb_token_image_style', $values['youtube_thumb_token_image_style'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.
YoutubeSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
YoutubeSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
YoutubeSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
YoutubeSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm