You are here

class DirectoryFetcherFeedForm in Feeds 8.3

Provides a form on the feed edit page for the DirectoryFetcher.

Hierarchy

Expanded class hierarchy of DirectoryFetcherFeedForm

1 file declares its use of DirectoryFetcherFeedForm
DirectoryFetcherFeedFormTest.php in tests/src/Unit/Feeds/Fetcher/Form/DirectoryFetcherFeedFormTest.php

File

src/Feeds/Fetcher/Form/DirectoryFetcherFeedForm.php, line 13

Namespace

Drupal\feeds\Feeds\Fetcher\Form
View source
class DirectoryFetcherFeedForm extends ExternalPluginFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    $args = [
      '%schemes' => implode(', ', $this->plugin
        ->getConfiguration('allowed_schemes')),
    ];
    $form['source'] = [
      '#title' => $this
        ->t('Server file or directory path'),
      '#type' => 'feeds_uri',
      '#default_value' => $feed
        ->getSource(),
      '#allowed_schemes' => $this->plugin
        ->getConfiguration('allowed_schemes'),
      '#description' => $this
        ->t('The allowed schemes are: %schemes', $args),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    $source = $form_state
      ->getValue('source');
    if (!is_readable($source) || !is_dir($source) && !is_file($source)) {
      $form_state
        ->setError($form['source'], $this
        ->t('%source is not a readable directory or file.', [
        '%source' => $source,
      ]));
      return;
    }
    if (is_dir($source)) {
      return;
    }
    $allowed = $this->plugin
      ->getConfiguration('allowed_extensions');

    // Validate a single file.
    if (!File::validateExtension($source, $allowed)) {
      $form_state
        ->setError($form['source'], $this
        ->t('%source has an invalid file extension.', [
        '%source' => $source,
      ]));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
    $feed
      ->setSource($form_state
      ->getValue('source'));
  }

}

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