public function HttpFetcherFeedForm::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/ HttpFetcherFeedForm.php, line 61
Class
- HttpFetcherFeedForm
- Provides a form on the feed edit page for the HttpFetcher.
Namespace
Drupal\feeds\Feeds\Fetcher\FormCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
try {
$url = Feed::translateSchemes($form_state
->getValue('source'));
} catch (\InvalidArgumentException $e) {
$form_state
->setError($form['source'], $this
->t("The url's scheme is not supported. Supported schemes are: @supported.", [
'@supported' => implode(', ', Feed::getSupportedSchemes()),
]));
// If the source doesn't have a valid scheme the rest of the validation
// isn't helpful. Break out early.
return;
}
$form_state
->setValue('source', $url);
if (!$this->plugin
->getConfiguration('auto_detect_feeds')) {
return;
}
try {
$response = $this->client
->get($url);
} catch (RequestException $e) {
$args = [
'%site' => $url,
'%error' => $e
->getMessage(),
];
$form_state
->setError($form['source'], $this
->t('The feed from %site seems to be broken because of error "%error".', $args));
return;
}
if ($url = Feed::getCommonSyndication($form_state
->getValue('source'), (string) $response
->getBody())) {
$form_state
->setValue('source', $url);
}
else {
$form_state
->setError($form['source'], $this
->t('Invalid feed URL.'));
}
}