DirectoryFetcherFeedForm.php in Feeds 8.3
File
src/Feeds/Fetcher/Form/DirectoryFetcherFeedForm.php
View source
<?php
namespace Drupal\feeds\Feeds\Fetcher\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\feeds\FeedInterface;
use Drupal\feeds\Plugin\Type\ExternalPluginFormBase;
use Drupal\feeds\Utility\File;
class DirectoryFetcherFeedForm extends ExternalPluginFormBase {
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;
}
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');
if (!File::validateExtension($source, $allowed)) {
$form_state
->setError($form['source'], $this
->t('%source has an invalid file extension.', [
'%source' => $source,
]));
}
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
$feed
->setSource($form_state
->getValue('source'));
}
}