You are here

public function HttpFetcherForm::buildConfigurationForm in Feeds 8.3

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

src/Feeds/Fetcher/Form/HttpFetcherForm.php, line 16

Class

HttpFetcherForm
The configuration form for http fetchers.

Namespace

Drupal\feeds\Feeds\Fetcher\Form

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['auto_detect_feeds'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Auto detect feeds'),
    '#description' => $this
      ->t('If the supplied URL does not point to a feed but an HTML document, attempt to extract a feed URL from the document.'),
    '#default_value' => $this->plugin
      ->getConfiguration('auto_detect_feeds'),
  ];
  $form['use_pubsubhubbub'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use PubSubHubbub'),
    '#description' => $this
      ->t('Attempt to use a <a href="http://en.wikipedia.org/wiki/PubSubHubbub">PubSubHubbub</a> subscription if available.'),
    '#default_value' => $this->plugin
      ->getConfiguration('use_pubsubhubbub'),
  ];
  $form['always_download'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Always download'),
    '#description' => $this
      ->t('Always download the feed, even if the feed has not been updated.'),
    '#default_value' => $this->plugin
      ->getConfiguration('always_download'),
  ];
  $form['fallback_hub'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('Fallback hub'),
    '#description' => $this
      ->t('Enter the URL of a fallback hub. <a href="https://pubsubhubbub.superfeedr.com">Superfeedr</a> is a good choice. If given, this hub will be used if a hub for the feed could not be found.'),
    '#default_value' => $this->plugin
      ->getConfiguration('fallback_hub'),
    '#states' => [
      'visible' => [
        'input[name="fetcher_configuration[use_pubsubhubbub]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];

  // Per feed type override of global http request timeout setting.
  $form['request_timeout'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Request timeout'),
    '#description' => $this
      ->t('Timeout in seconds to wait for an HTTP request to finish.'),
    '#default_value' => $this->plugin
      ->getConfiguration('request_timeout'),
    '#min' => 0,
  ];
  return $form;
}