You are here

class FeedsYouTubeFetcherForm in Feeds: YouTube Parser 8

The configuration form for YouTube fetchers.

Hierarchy

Expanded class hierarchy of FeedsYouTubeFetcherForm

File

src/Feeds/Fetcher/Form/FeedsYouTubeFetcherForm.php, line 11

Namespace

Drupal\feeds_youtube\Feeds\Fetcher\Form
View source
class FeedsYouTubeFetcherForm extends ExternalPluginFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $config = $this->plugin
      ->getConfiguration();
    $form['google_developer_key'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('API key'),
      '#description' => $this
        ->t('Google API Key'),
      '#default_value' => $config['google_developer_key'],
      '#required' => TRUE,
    ];
    $form['google_oauth_client_id'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Client ID'),
      '#description' => $this
        ->t('Google OAuth 2.0 Client ID'),
      '#default_value' => $config['google_oauth_client_id'],
      '#required' => TRUE,
    ];
    $form['google_oauth_client_secret'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Client secret'),
      '#description' => $this
        ->t('Google OAuth 2.0 Client secret'),
      '#default_value' => $config['google_oauth_client_secret'],
      '#required' => TRUE,
    ];
    $form['import_video_limit'] = array(
      '#type' => 'number',
      '#min' => 1,
      '#title' => t('Limit the total number of imported videos'),
      '#description' => t('Specify a limit for the total number of videos to import from YouTube.'),
      '#default_value' => $config['import_video_limit'],
      '#required' => TRUE,
    );
    $form['results_per_page'] = array(
      '#type' => 'number',
      '#min' => 1,
      '#max' => 50,
      '#title' => $this
        ->t('Limit videos per API request'),
      '#description' => $this
        ->t('Limit the number of retrieved videos per API request.'),
      '#default_value' => $config['results_per_page'],
      '#required' => TRUE,
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {

    // Trim all values before saving.
    $values = $form_state
      ->getValues();
    foreach ($values as &$value) {
      if (is_string($value)) {
        $value = trim($value);
      }
    }
    $this->plugin
      ->setConfiguration($values);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
ExternalPluginFormBase::$plugin protected property The Feeds plugin.
ExternalPluginFormBase::setPlugin public function Sets the plugin for this object. Overrides PluginAwareInterface::setPlugin
ExternalPluginFormBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 5
FeedsYouTubeFetcherForm::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
FeedsYouTubeFetcherForm::submitConfigurationForm public function Form submission handler. Overrides ExternalPluginFormBase::submitConfigurationForm
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.