function ViewEditForm::getDisplayDetails
Same name in other branches
- 9 core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::getDisplayDetails()
- 8.9.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::getDisplayDetails()
- 11.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::getDisplayDetails()
Helper function to get the display details section of the edit UI.
Parameters
\Drupal\views_ui\ViewUI $view: The ViewUI entity.
array $display: The display.
Return value
array A renderable page build array.
1 call to ViewEditForm::getDisplayDetails()
- ViewEditForm::getDisplayTab in core/
modules/ views_ui/ src/ ViewEditForm.php - Returns a renderable array representing the edit page for one display.
File
-
core/
modules/ views_ui/ src/ ViewEditForm.php, line 423
Class
- ViewEditForm
- Form controller for the Views edit form.
Namespace
Drupal\views_uiCode
public function getDisplayDetails($view, $display) {
$display_title = $this->getDisplayLabel($view, $display['id'], FALSE);
$build = [
'#theme_wrappers' => [
'container',
],
'#attributes' => [
'id' => 'edit-display-settings-details',
],
];
$is_display_deleted = !empty($display['deleted']);
// The default display cannot be duplicated.
$is_default = $display['id'] == 'default';
// @todo Figure out why getOption doesn't work here.
$is_enabled = $view->getExecutable()->displayHandlers
->get($display['id'])
->isEnabled();
if ($display['id'] != 'default') {
$build['top']['#theme_wrappers'] = [
'container',
];
$build['top']['#attributes']['id'] = 'edit-display-settings-top';
$build['top']['#attributes']['class'] = [
'views-ui-display-tab-actions',
'edit-display-settings-top',
'views-ui-display-tab-bucket',
'clearfix',
];
// The Delete, Duplicate and Undo Delete buttons.
$build['top']['actions'] = [
'#theme_wrappers' => [
'dropbutton_wrapper',
],
];
// Because some of the 'links' are actually submit buttons, we have to
// manually wrap each item in <li> and the whole list in <ul>.
$build['top']['actions']['prefix']['#markup'] = '<ul class="dropbutton">';
if (!$is_display_deleted) {
if (!$is_enabled) {
$build['top']['actions']['enable'] = [
'#type' => 'submit',
'#value' => $this->t('Enable @display_title', [
'@display_title' => $display_title,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDisplayEnable',
'::submitDelayDestination',
],
'#prefix' => '<li class="enable">',
"#suffix" => '</li>',
];
}
elseif ($view->status() && $view->getExecutable()->displayHandlers
->get($display['id'])
->hasPath()) {
$path = $view->getExecutable()->displayHandlers
->get($display['id'])
->getPath();
if ($path && !str_contains($path, '%')) {
// Wrap this in a try/catch as trying to generate links to some
// routes may throw an exception, for example if they do not
// respond to HTML, such as RESTExports.
try {
if (!parse_url($path, PHP_URL_SCHEME)) {
// @todo Views should expect and store a leading /. See:
// https://www.drupal.org/node/2423913
$url = Url::fromUserInput('/' . ltrim($path, '/'));
}
else {
$url = Url::fromUri("base:{$path}");
}
} catch (BadRequestException|NotAcceptableHttpException $e) {
$url = '/' . $path;
}
$build['top']['actions']['path'] = [
'#type' => 'link',
'#title' => $this->t('View @display_title', [
'@display_title' => $display_title,
]),
'#options' => [
'alt' => [
$this->t("Go to the real page for this display"),
],
],
'#url' => $url,
'#prefix' => '<li class="view">',
"#suffix" => '</li>',
];
}
}
if (!$is_default) {
$build['top']['actions']['duplicate'] = [
'#type' => 'submit',
'#value' => $this->t('Duplicate @display_title', [
'@display_title' => $display_title,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDisplayDuplicate',
'::submitDelayDestination',
],
'#prefix' => '<li class="duplicate">',
"#suffix" => '</li>',
];
}
// Always allow a display to be deleted.
$build['top']['actions']['delete'] = [
'#type' => 'submit',
'#value' => $this->t('Delete @display_title', [
'@display_title' => $display_title,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDisplayDelete',
'::submitDelayDestination',
],
'#prefix' => '<li class="delete">',
"#suffix" => '</li>',
];
foreach (Views::fetchPluginNames('display', NULL, [
$view->get('storage')
->get('base_table'),
]) as $type => $label) {
if ($type == $display['display_plugin']) {
continue;
}
$build['top']['actions']['duplicate_as'][$type] = [
'#type' => 'submit',
'#value' => $this->t('Duplicate as @type', [
'@type' => $label,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDuplicateDisplayAsType',
'::submitDelayDestination',
],
'#prefix' => '<li class="duplicate">',
'#suffix' => '</li>',
];
}
}
else {
$build['top']['actions']['undo_delete'] = [
'#type' => 'submit',
'#value' => $this->t('Undo delete of @display_title', [
'@display_title' => $display_title,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDisplayUndoDelete',
'::submitDelayDestination',
],
'#prefix' => '<li class="undo-delete">',
"#suffix" => '</li>',
];
}
if ($is_enabled) {
$build['top']['actions']['disable'] = [
'#type' => 'submit',
'#value' => $this->t('Disable @display_title', [
'@display_title' => $display_title,
]),
'#limit_validation_errors' => [],
'#submit' => [
'::submitDisplayDisable',
'::submitDelayDestination',
],
'#prefix' => '<li class="disable">',
"#suffix" => '</li>',
];
}
$build['top']['actions']['suffix']['#markup'] = '</ul>';
// The area above the three columns.
$build['top']['display_title'] = [
'#theme' => 'views_ui_display_tab_setting',
'#description' => $this->t('Display name'),
'#link' => $view->getExecutable()->displayHandlers
->get($display['id'])
->optionLink($display_title, 'display_title'),
];
}
$build['columns'] = [];
$build['columns']['#theme_wrappers'] = [
'container',
];
$build['columns']['#attributes'] = [
'id' => 'edit-display-settings-main',
'class' => [
'clearfix',
'views-display-columns',
],
];
$build['columns']['first']['#theme_wrappers'] = [
'container',
];
$build['columns']['first']['#attributes'] = [
'class' => [
'views-display-column',
'first',
],
];
$build['columns']['second']['#theme_wrappers'] = [
'container',
];
$build['columns']['second']['#attributes'] = [
'class' => [
'views-display-column',
'second',
],
];
$build['columns']['second']['settings'] = [];
$build['columns']['second']['header'] = [];
$build['columns']['second']['footer'] = [];
$build['columns']['second']['empty'] = [];
$build['columns']['second']['pager'] = [];
// The third column buckets are wrapped in details.
$build['columns']['third'] = [
'#type' => 'details',
'#title' => $this->t('Advanced'),
'#theme_wrappers' => [
'details',
],
'#attributes' => [
'class' => [
'views-display-column',
'third',
],
],
];
// Collapse the details by default.
$build['columns']['third']['#open'] = \Drupal::config('views.settings')->get('ui.show.advanced_column');
// Each option (e.g. title, access, display as grid/table/list) fits into one
// of several "buckets," or boxes (Format, Fields, Sort, and so on).
$buckets = [];
// Fetch options from the display plugin, with a list of buckets they go into.
$options = [];
$view->getExecutable()->displayHandlers
->get($display['id'])
->optionsSummary($buckets, $options);
// Place each option into its bucket.
foreach ($options as $id => $option) {
// Each option self-identifies as belonging in a particular bucket.
$buckets[$option['category']]['build'][$id] = $this->buildOptionForm($view, $id, $option, $display);
}
// Place each bucket into the proper column.
foreach ($buckets as $id => $bucket) {
// Let buckets identify themselves as belonging in a column.
if (isset($bucket['column']) && isset($build['columns'][$bucket['column']])) {
$column = $bucket['column'];
}
else {
$column = 'third';
}
if (isset($bucket['build']) && is_array($bucket['build'])) {
$build['columns'][$column][$id] = $bucket['build'];
$build['columns'][$column][$id]['#theme_wrappers'][] = 'views_ui_display_tab_bucket';
$build['columns'][$column][$id]['#title'] = !empty($bucket['title']) ? $bucket['title'] : '';
$build['columns'][$column][$id]['#name'] = $id;
}
}
$build['columns']['first']['fields'] = $this->getFormBucket($view, 'field', $display);
$build['columns']['first']['filters'] = $this->getFormBucket($view, 'filter', $display);
$build['columns']['first']['sorts'] = $this->getFormBucket($view, 'sort', $display);
$build['columns']['second']['header'] = $this->getFormBucket($view, 'header', $display);
$build['columns']['second']['footer'] = $this->getFormBucket($view, 'footer', $display);
$build['columns']['second']['empty'] = $this->getFormBucket($view, 'empty', $display);
$build['columns']['third']['relationships'] = $this->getFormBucket($view, 'relationship', $display);
$build['columns']['third']['arguments'] = $this->getFormBucket($view, 'argument', $display);
// If there is a contextual filter or a relationship set, expand the
// Advanced column to display these values to the user.
if (!empty($build['columns']['third']['relationships']['fields']) || !empty($build['columns']['third']['arguments']['fields'])) {
$build['columns']['third']['#open'] = TRUE;
}
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.