function views_ui_standard_display_dropdown
Same name in other branches
- 8.9.x core/modules/views_ui/admin.inc \views_ui_standard_display_dropdown()
- 10 core/modules/views_ui/admin.inc \views_ui_standard_display_dropdown()
- 11.x core/modules/views_ui/admin.inc \views_ui_standard_display_dropdown()
Adds an element to select either the default display or the current display.
5 calls to views_ui_standard_display_dropdown()
- AddHandler::buildForm in core/
modules/ views_ui/ src/ Form/ Ajax/ AddHandler.php - Form constructor.
- ConfigHandler::buildForm in core/
modules/ views_ui/ src/ Form/ Ajax/ ConfigHandler.php - Form constructor.
- DisplayPluginBase::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ display/ DisplayPluginBase.php - Provide a form to edit options for this plugin.
- Rearrange::buildForm in core/
modules/ views_ui/ src/ Form/ Ajax/ Rearrange.php - Form constructor.
- RearrangeFilter::buildForm in core/
modules/ views_ui/ src/ Form/ Ajax/ RearrangeFilter.php - Form constructor.
File
-
core/
modules/ views_ui/ admin.inc, line 205
Code
function views_ui_standard_display_dropdown(&$form, FormStateInterface $form_state, $section) {
$view = $form_state->get('view');
$display_id = $form_state->get('display_id');
$executable = $view->getExecutable();
$displays = $executable->displayHandlers;
$current_display = $executable->display_handler;
// @todo Move this to a separate function if it's needed on any forms that
// don't have the display dropdown.
$form['override'] = [
'#prefix' => '<div class="views-override clearfix form--inline views-offset-top" data-drupal-views-offset="top">',
'#suffix' => '</div>',
'#weight' => -1000,
'#tree' => TRUE,
];
// Add the "2 of 3" progress indicator.
if ($form_progress = $view->getFormProgress()) {
$arguments = $form['#title']->getArguments() + [
'@current' => $form_progress['current'],
'@total' => $form_progress['total'],
];
$form['#title'] = t('Configure @type @current of @total: @item', $arguments);
}
// The dropdown should not be added when :
// - this is the default display.
// - there is no default shown and just one additional display (mostly page)
// and the current display is defaulted.
if ($current_display->isDefaultDisplay() || $current_display->isDefaulted($section) && !\Drupal::config('views.settings')->get('ui.show.default_display') && count($displays) <= 2) {
return;
}
// Determine whether any other displays have overrides for this section.
$section_overrides = FALSE;
$section_defaulted = $current_display->isDefaulted($section);
foreach ($displays as $id => $display) {
if ($id === 'default' || $id === $display_id) {
continue;
}
if ($display && !$display->isDefaulted($section)) {
$section_overrides = TRUE;
}
}
$display_dropdown['default'] = $section_overrides ? t('All displays (except overridden)') : t('All displays');
$display_dropdown[$display_id] = t('This @display_type (override)', [
'@display_type' => $current_display->getPluginId(),
]);
// Only display the revert option if we are in an overridden section.
if (!$section_defaulted) {
$display_dropdown['default_revert'] = t('Revert to default');
}
$form['override']['dropdown'] = [
'#type' => 'select',
// @TODO: Translators may need more context than this.
'#title' => t('For'),
'#options' => $display_dropdown,
];
if ($current_display->isDefaulted($section)) {
$form['override']['dropdown']['#default_value'] = 'defaults';
}
else {
$form['override']['dropdown']['#default_value'] = $display_id;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.