class HttpFetcherFeedForm in Feeds 8.3
Provides a form on the feed edit page for the HttpFetcher.
Hierarchy
- class \Drupal\feeds\Plugin\Type\ExternalPluginFormBase implements PluginFormInterface, PluginAwareInterface uses DependencySerializationTrait, StringTranslationTrait- class \Drupal\feeds\Feeds\Fetcher\Form\HttpFetcherFeedForm implements ContainerInjectionInterface
 
Expanded class hierarchy of HttpFetcherFeedForm
File
- src/Feeds/ Fetcher/ Form/ HttpFetcherFeedForm.php, line 17 
Namespace
Drupal\feeds\Feeds\Fetcher\FormView source
class HttpFetcherFeedForm extends ExternalPluginFormBase implements ContainerInjectionInterface {
  /**
   * The Guzzle client.
   *
   * @var \GuzzleHttp\ClientInterface
   */
  protected $client;
  /**
   * Constructs an HttpFeedForm object.
   *
   * @param \GuzzleHttp\ClientInterface $client
   *   The HTTP client.
   */
  public function __construct(ClientInterface $client) {
    $this->client = $client;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('http_client'));
  }
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    $form['source'] = [
      '#title' => $this
        ->t('Feed URL'),
      '#type' => 'url',
      '#default_value' => $feed
        ->getSource(),
      '#maxlength' => 2048,
      '#required' => TRUE,
    ];
    return $form;
  }
  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    try {
      $url = Feed::translateSchemes($form_state
        ->getValue('source'));
    } catch (\InvalidArgumentException $e) {
      $form_state
        ->setError($form['source'], $this
        ->t("The url's scheme is not supported. Supported schemes are: @supported.", [
        '@supported' => implode(', ', Feed::getSupportedSchemes()),
      ]));
      // If the source doesn't have a valid scheme the rest of the validation
      // isn't helpful. Break out early.
      return;
    }
    $form_state
      ->setValue('source', $url);
    if (!$this->plugin
      ->getConfiguration('auto_detect_feeds')) {
      return;
    }
    try {
      $response = $this->client
        ->get($url);
    } catch (RequestException $e) {
      $args = [
        '%site' => $url,
        '%error' => $e
          ->getMessage(),
      ];
      $form_state
        ->setError($form['source'], $this
        ->t('The feed from %site seems to be broken because of error "%error".', $args));
      return;
    }
    if ($url = Feed::getCommonSyndication($form_state
      ->getValue('source'), (string) $response
      ->getBody())) {
      $form_state
        ->setValue('source', $url);
    }
    else {
      $form_state
        ->setError($form['source'], $this
        ->t('Invalid feed URL.'));
    }
  }
  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    $feed
      ->setSource($form_state
      ->getValue('source'));
  }
  /**
   * Performs a GET request.
   *
   * @param string $url
   *   The URL to GET.
   *
   * @return \Guzzle\Http\Message\Response
   *   A Guzzle response.
   *
   * @throws \RuntimeException
   *   Thrown if the GET request failed.
   */
  protected function get($url) {
    try {
      $response = $this->client
        ->get(Feed::translateSchemes($url));
    } catch (RequestException $e) {
      $args = [
        '%site' => $url,
        '%error' => $e
          ->getMessage(),
      ];
      throw new \RuntimeException($this
        ->t('The feed from %site seems to be broken because of error "%error".', $args));
    }
    return $response;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DependencySerializationTrait:: | protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| DependencySerializationTrait:: | protected | property | An array of service IDs keyed by property name used for serialization. | |
| DependencySerializationTrait:: | public | function | 1 | |
| DependencySerializationTrait:: | public | function | 2 | |
| ExternalPluginFormBase:: | protected | property | The Feeds plugin. | |
| ExternalPluginFormBase:: | public | function | Sets the plugin for this object. Overrides PluginAwareInterface:: | |
| HttpFetcherFeedForm:: | protected | property | The Guzzle client. | |
| HttpFetcherFeedForm:: | public | function | Form constructor. Overrides PluginFormInterface:: | |
| HttpFetcherFeedForm:: | public static | function | Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: | |
| HttpFetcherFeedForm:: | protected | function | Performs a GET request. | |
| HttpFetcherFeedForm:: | public | function | Form submission handler. Overrides ExternalPluginFormBase:: | |
| HttpFetcherFeedForm:: | public | function | Form validation handler. Overrides ExternalPluginFormBase:: | |
| HttpFetcherFeedForm:: | public | function | Constructs an HttpFeedForm object. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | 
