public function DisplayLink::validate in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::validate()
- 9 core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::validate()
File
- core/
modules/ views/ src/ Plugin/ views/ area/ DisplayLink.php, line 88
Class
- DisplayLink
- Views area display_link handler.
Namespace
Drupal\views\Plugin\views\areaCode
public function validate() {
$errors = parent::validate();
// Do not add errors for the default display if it is not displayed in the
// UI.
if ($this->displayHandler
->isDefaultDisplay() && !\Drupal::config('views.settings')
->get('ui.show.default_display')) {
return $errors;
}
// Ajax errors can cause the plugin to be added without any settings.
$linked_display_id = !empty($this->options['display_id']) ? $this->options['display_id'] : NULL;
if (!$linked_display_id) {
$errors[] = $this
->t('%current_display: The link in the %area area has no configured display.', [
'%current_display' => $this->displayHandler->display['display_title'],
'%area' => $this->areaType,
]);
return $errors;
}
// Check if the linked display hasn't been removed.
if (!$this->view->displayHandlers
->get($linked_display_id)) {
$errors[] = $this
->t('%current_display: The link in the %area area points to the %linked_display display which no longer exists.', [
'%current_display' => $this->displayHandler->display['display_title'],
'%area' => $this->areaType,
'%linked_display' => $this->options['display_id'],
]);
return $errors;
}
// Check if the linked display is a path-based display.
if (!$this
->isPathBasedDisplay($linked_display_id)) {
$errors[] = $this
->t('%current_display: The link in the %area area points to the %linked_display display which does not have a path.', [
'%current_display' => $this->displayHandler->display['display_title'],
'%area' => $this->areaType,
'%linked_display' => $this->view->displayHandlers
->get($linked_display_id)->display['display_title'],
]);
return $errors;
}
// Check if options of the linked display are equal to the options of the
// current display. We "only" show a warning here, because even though we
// recommend keeping the display options equal, we do not want to enforce
// this.
$unequal_options = [
'filters' => t('Filter criteria'),
'sorts' => t('Sort criteria'),
'pager' => t('Pager'),
'arguments' => t('Contextual filters'),
];
foreach (array_keys($unequal_options) as $option) {
if ($this
->hasEqualOptions($linked_display_id, $option)) {
unset($unequal_options[$option]);
}
}
if ($unequal_options) {
$warning = $this
->t('%current_display: The link in the %area area points to the %linked_display display which uses different settings than the %current_display display for: %unequal_options. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', [
'%current_display' => $this->displayHandler->display['display_title'],
'%area' => $this->areaType,
'%linked_display' => $this->view->displayHandlers
->get($linked_display_id)->display['display_title'],
'%unequal_options' => implode(', ', $unequal_options),
]);
$this
->messenger()
->addWarning($warning);
}
return $errors;
}