You are here

class DirectoryFetcherForm in Feeds 8.3

Defines a directory fetcher.

Hierarchy

Expanded class hierarchy of DirectoryFetcherForm

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

File

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

Namespace

Drupal\feeds\Feeds\Fetcher\Form
View source
class DirectoryFetcherForm extends ExternalPluginFormBase implements ContainerInjectionInterface {

  /**
   * The stream wrapper manager.
   *
   * @var \Drupal\Core\StreamWrapper\StreamWrapperManager
   */
  protected $streamWrapperManager;

  /**
   * Constructs a DirectoryFetcherForm object.
   *
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManager $stream_wrapper_manager
   *   The stream wrapper manager.
   */
  public function __construct(StreamWrapperManager $stream_wrapper_manager) {
    $this->streamWrapperManager = $stream_wrapper_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('stream_wrapper_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['allowed_extensions'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Allowed file extensions'),
      '#description' => $this
        ->t('Allowed file extensions for upload.'),
      '#default_value' => $this->plugin
        ->getConfiguration('allowed_extensions'),
    ];
    $form['allowed_schemes'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Allowed schemes'),
      '#default_value' => $this->plugin
        ->getConfiguration('allowed_schemes'),
      '#options' => $this
        ->getSchemeOptions(),
      '#description' => $this
        ->t('Select the schemes you want to allow for direct upload.'),
    ];
    $form['recursive_scan'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Search recursively'),
      '#default_value' => $this->plugin
        ->getConfiguration('recursive_scan'),
      '#description' => $this
        ->t('Search through sub-directories.'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    $form_state
      ->setValue('allowed_schemes', array_filter($form_state
      ->getValue('allowed_schemes', [])));
    $extensions = preg_replace('/\\s+/', ' ', trim($form_state
      ->getValue('allowed_extensions', '')));
    $form_state
      ->setValue('allowed_extensions', $extensions);
  }

  /**
   * Returns available scheme options for use in checkboxes or select list.
   *
   * @return array
   *   The available scheme array keyed scheme => description.
   */
  protected function getSchemeOptions() {
    $options = [];
    foreach ($this->streamWrapperManager
      ->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE) as $scheme => $description) {
      $options[$scheme] = Html::escape($scheme . ': ' . $description);
    }
    return $options;
  }

}

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
DirectoryFetcherForm::$streamWrapperManager protected property The stream wrapper manager.
DirectoryFetcherForm::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
DirectoryFetcherForm::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DirectoryFetcherForm::getSchemeOptions protected function Returns available scheme options for use in checkboxes or select list.
DirectoryFetcherForm::validateConfigurationForm public function Form validation handler. Overrides ExternalPluginFormBase::validateConfigurationForm
DirectoryFetcherForm::__construct public function Constructs a DirectoryFetcherForm object.
ExternalPluginFormBase::$plugin protected property The Feeds plugin.
ExternalPluginFormBase::setPlugin public function Sets the plugin for this object. Overrides PluginAwareInterface::setPlugin
ExternalPluginFormBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 4
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.