function DisplayPluginBase::validate
Same name in other branches
- 9 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validate()
- 8.9.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validate()
- 11.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validate()
Overrides PluginBase::validate
3 calls to DisplayPluginBase::validate()
- DisplayTest::validate in core/
modules/ views/ tests/ modules/ views_test_data/ src/ Plugin/ views/ display/ DisplayTest.php - Validate that the plugin is correct and can be saved.
- EntityReference::validate in core/
modules/ views/ src/ Plugin/ views/ display/ EntityReference.php - Validate that the plugin is correct and can be saved.
- PathPluginBase::validate in core/
modules/ views/ src/ Plugin/ views/ display/ PathPluginBase.php - Validate that the plugin is correct and can be saved.
3 methods override DisplayPluginBase::validate()
- DisplayTest::validate in core/
modules/ views/ tests/ modules/ views_test_data/ src/ Plugin/ views/ display/ DisplayTest.php - Validate that the plugin is correct and can be saved.
- EntityReference::validate in core/
modules/ views/ src/ Plugin/ views/ display/ EntityReference.php - Validate that the plugin is correct and can be saved.
- PathPluginBase::validate in core/
modules/ views/ src/ Plugin/ views/ display/ PathPluginBase.php - Validate that the plugin is correct and can be saved.
File
-
core/
modules/ views/ src/ Plugin/ views/ display/ DisplayPluginBase.php, line 2480
Class
- DisplayPluginBase
- Base class for views display plugins.
Namespace
Drupal\views\Plugin\views\displayCode
public function validate() {
$errors = [];
// Make sure displays that use fields HAVE fields.
if ($this->usesFields()) {
$fields = FALSE;
foreach ($this->getHandlers('field') as $field) {
if (empty($field->options['exclude'])) {
$fields = TRUE;
}
}
if (!$fields) {
$errors[] = $this->t('Display "@display" uses fields but there are none defined for it or all are excluded.', [
'@display' => $this->display['display_title'],
]);
}
}
// Validate the more link.
if ($this->isMoreEnabled() && $this->getOption('link_display') !== 'custom_url') {
$routed_display = $this->getRoutedDisplay();
if (!$routed_display || !$routed_display->isEnabled()) {
$errors[] = $this->t('Display "@display" uses a "more" link but there are no displays it can link to. You need to specify a custom URL.', [
'@display' => $this->display['display_title'],
]);
}
}
if ($this->hasPath() && !$this->getOption('path')) {
$errors[] = $this->t('Display "@display" uses a path but the path is undefined.', [
'@display' => $this->display['display_title'],
]);
}
// Validate style plugin.
$style = $this->getPlugin('style');
if (empty($style)) {
$errors[] = $this->t('Display "@display" has an invalid style plugin.', [
'@display' => $this->display['display_title'],
]);
}
else {
$result = $style->validate();
if (!empty($result) && is_array($result)) {
$errors = array_merge($errors, $result);
}
}
// Validate query plugin.
$query = $this->getPlugin('query');
$result = $query->validate();
if (!empty($result) && is_array($result)) {
$errors = array_merge($errors, $result);
}
// Check for missing relationships.
$relationships = array_keys($this->getHandlers('relationship'));
foreach (ViewExecutable::getHandlerTypes() as $type => $handler_type_info) {
foreach ($this->getHandlers($type) as $handler) {
if (!empty($handler->options['relationship']) && $handler->options['relationship'] != 'none' && !in_array($handler->options['relationship'], $relationships)) {
$errors[] = $this->t('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', [
'%relationship_name' => $handler->options['relationship'],
'%handler_type' => $handler_type_info['lstitle'],
'%handler' => $handler->adminLabel(),
'%display_name' => $this->display['display_title'],
]);
}
}
}
// Validate handlers.
foreach (ViewExecutable::getHandlerTypes() as $type => $info) {
foreach ($this->getHandlers($type) as $handler) {
$result = $handler->validate();
if (!empty($result) && is_array($result)) {
$errors = array_merge($errors, $result);
}
}
}
// Validate extenders.
foreach ($this->extenders as $extender) {
$result = $extender->validate();
if (!empty($result) && is_array($result)) {
$errors = array_merge($errors, $result);
}
}
return $errors;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.