class DirectoryFetcherFeedForm in Feeds 8.3
Provides a form on the feed edit page for the DirectoryFetcher.
Hierarchy
- class \Drupal\feeds\Plugin\Type\ExternalPluginFormBase implements PluginFormInterface, PluginAwareInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\feeds\Feeds\Fetcher\Form\DirectoryFetcherFeedForm
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\FormView 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
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 | |
DirectoryFetcherFeedForm:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
DirectoryFetcherFeedForm:: |
public | function |
Form submission handler. Overrides ExternalPluginFormBase:: |
|
DirectoryFetcherFeedForm:: |
public | function |
Form validation handler. Overrides ExternalPluginFormBase:: |
|
ExternalPluginFormBase:: |
protected | property | The Feeds plugin. | |
ExternalPluginFormBase:: |
public | function |
Sets the plugin for this object. Overrides PluginAwareInterface:: |
|
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. |