public function DirectoryFetcherFeedForm::validateConfigurationForm in Feeds 8.3
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides ExternalPluginFormBase::validateConfigurationForm
File
- src/
Feeds/ Fetcher/ Form/ DirectoryFetcherFeedForm.php, line 35
Class
- DirectoryFetcherFeedForm
- Provides a form on the feed edit page for the DirectoryFetcher.
Namespace
Drupal\feeds\Feeds\Fetcher\FormCode
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,
]));
}
}