class UploadFetcherForm in Feeds 8.3
The configuration form for the upload fetcher.
Hierarchy
- class \Drupal\feeds\Plugin\Type\ExternalPluginFormBase implements PluginFormInterface, PluginAwareInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\feeds\Feeds\Fetcher\Form\UploadFetcherForm implements ContainerInjectionInterface
Expanded class hierarchy of UploadFetcherForm
1 file declares its use of UploadFetcherForm
- UploadFetcherFormTest.php in tests/
src/ Unit/ Feeds/ Fetcher/ Form/ UploadFetcherFormTest.php
File
- src/
Feeds/ Fetcher/ Form/ UploadFetcherForm.php, line 17
Namespace
Drupal\feeds\Feeds\Fetcher\FormView source
class UploadFetcherForm extends ExternalPluginFormBase implements ContainerInjectionInterface {
/**
* The stream wrapper manager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* The file and stream wrapper helper.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Constructs a DirectoryFetcherForm object.
*
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file and stream wrapper helper.
*/
public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) {
$this->streamWrapperManager = $stream_wrapper_manager;
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('stream_wrapper_manager'), $container
->get('file_system'));
}
/**
* {@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['directory'] = [
'#type' => 'feeds_uri',
'#title' => $this
->t('Upload directory'),
'#description' => $this
->t('Directory where uploaded files get stored. Prefix the path with a scheme. Available schemes: @schemes.', [
'@schemes' => implode(', ', $this
->getSchemes()),
]),
'#default_value' => $this->plugin
->getConfiguration('directory'),
'#required' => TRUE,
'#allowed_schemes' => $this
->getSchemes(),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values =& $form_state
->getValues();
$values['allowed_extensions'] = preg_replace('/\\s+/', ' ', trim($values['allowed_extensions']));
// Ensure that the upload directory exists.
if (!empty($form['directory']) && !$this->fileSystem
->prepareDirectory($values['directory'], FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
$form_state
->setError($form['directory'], $this
->t('The chosen directory does not exist and attempts to create it failed.'));
}
}
/**
* 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;
}
/**
* Returns available schemes.
*
* @return string[]
* The available schemes.
*/
protected function getSchemes() {
return array_keys($this->streamWrapperManager
->getWrappers(StreamWrapperInterface::WRITE_VISIBLE));
}
}
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:: |
|
ExternalPluginFormBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
4 |
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. | |
UploadFetcherForm:: |
protected | property | The file and stream wrapper helper. | |
UploadFetcherForm:: |
protected | property | The stream wrapper manager. | |
UploadFetcherForm:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
UploadFetcherForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
UploadFetcherForm:: |
protected | function | Returns available scheme options for use in checkboxes or select list. | |
UploadFetcherForm:: |
protected | function | Returns available schemes. | |
UploadFetcherForm:: |
public | function |
Form validation handler. Overrides ExternalPluginFormBase:: |
|
UploadFetcherForm:: |
public | function | Constructs a DirectoryFetcherForm object. |