function views_rss_core_views_rss_options_form_validate in Views RSS 8.2
Same name and namespace in other branches
- 8.3 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()
- 6.2 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()
- 7.2 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()
Implements hook_views_rss_options_form_validate().
File
- modules/
views_rss_core/ views_rss_core.module, line 241 - Provides core <channel> and <item> elements for Views RSS module.
Code
function views_rss_core_views_rss_options_form_validate($form, $form_state) {
$form_state_values = $form_state
->getValues();
// Validate channel <image> element.
if (!empty($form_state_values['style_options']['channel']['core']['views_rss_core']['image'])) {
// Do not validate absolute URLs, as this could mean external image.
if (!UrlHelper::isValid($form_state_values['style_options']['channel']['core']['views_rss_core']['image'], TRUE)) {
// Check that image exists and is in acceptable format.
$image = \Drupal::service('image.factory')
->get($form_state_values['style_options']['channel']['core']['views_rss_core']['image']);
if (!$image
->isValid()) {
$form_state
->setErrorByName('style_options][channel][core][views_rss_core][image', t('Unable to find %image or incorrect image format.', array(
'%image' => $form_state_values['style_options']['channel']['core']['views_rss_core']['image'],
)));
}
else {
// Check image width.
if ($image
->getWidth() > 144) {
$form_state
->setErrorByName('style_options][channel][core][views_rss_core][image', t("Maximum allowed width of an image for feed channel's <image> element is 144 pixels. Specified %image is !width pixels wide.", array(
'%image' => $form_state_values['style_options']['channel']['core']['views_rss_core']['image'],
'%width' => $image
->getWidth(),
)));
}
// Check image height.
if ($image->info['height'] > 400) {
$form_state
->setErrorByName('style_options][channel][core][views_rss_core][image', t("Maximum allowed height of an image for feed channel's <image> element is 400 pixels. Specified %image is !height pixels high.", array(
'%image' => $form_state_values['style_options']['channel']['core']['views_rss_core']['image'],
'%height' => $image
->getHeight(),
)));
}
}
}
}
// Validate channel <docs> element.
if (!empty($form_state_values['style_options']['channel']['core']['views_rss_core']['docs'])) {
if (!UrlHelper::isValid($form_state_values['style_options']['channel']['core']['views_rss_core']['docs'], TRUE)) {
$form_state
->setErrorByName('style_options][channel][core][views_rss_core][docs', t("Not a valid URL."));
}
}
}