view = $view; // Load extenders as soon as possible. $display['display_options'] += ['display_extenders' => []]; $this->extenders = []; if ($extenders = Views::getEnabledDisplayExtenders()) { $manager = Views::pluginManager('display_extender'); $display_extender_options = $display['display_options']['display_extenders']; foreach ($extenders as $extender) { /** @var \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase $plugin */ if ($plugin = $manager->createInstance($extender)) { $extender_options = isset($display_extender_options[$plugin->getPluginId()]) ? $display_extender_options[$plugin->getPluginId()] : []; $plugin->init($this->view, $this, $extender_options); $this->extenders[$extender] = $plugin; } } } $this->setOptionDefaults($this->options, $this->defineOptions()); $this->display = &$display; // Track changes that the user should know about. $changed = FALSE; if (!isset($options) && isset($display['display_options'])) { $options = $display['display_options']; } if ($this->isDefaultDisplay() && isset($options['defaults'])) { unset($options['defaults']); } $skip_cache = \Drupal::config('views.settings')->get('skip_cache'); if (empty($view->editing) || !$skip_cache) { $cid = 'views:unpack_options:' . hash('sha256', serialize([$this->options, $options])) . ':' . \Drupal::languageManager()->getCurrentLanguage()->getId(); if (empty(static::$unpackOptions[$cid])) { $cache = \Drupal::cache('data')->get($cid); if (!empty($cache->data)) { $this->options = $cache->data; } else { $this->unpackOptions($this->options, $options); \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, $this->view->storage->getCacheTags()); } static::$unpackOptions[$cid] = $this->options; } else { $this->options = static::$unpackOptions[$cid]; } } else { $this->unpackOptions($this->options, $options); } // Mark the view as changed so the user has a chance to save it. if ($changed) { $this->view->changed = TRUE; } } /** * {@inheritdoc} */ public function destroy() { parent::destroy(); foreach ($this->handlers as $type => $handlers) { foreach ($handlers as $id => $handler) { if (is_object($handler)) { $this->handlers[$type][$id]->destroy(); } } } if (isset($this->default_display)) { unset($this->default_display); } foreach ($this->extenders as $extender) { $extender->destroy(); } } /** * {@inheritdoc} */ public function isDefaultDisplay() { return FALSE; } /** * {@inheritdoc} */ public function usesExposed() { if (!isset($this->has_exposed)) { foreach ($this->handlers as $type => $value) { foreach ($this->view->$type as $handler) { if ($handler->canExpose() && $handler->isExposed()) { // One is all we need; if we find it, return TRUE. $this->has_exposed = TRUE; return TRUE; } } } $pager = $this->getPlugin('pager'); if (isset($pager) && $pager->usesExposed()) { $this->has_exposed = TRUE; return TRUE; } $this->has_exposed = FALSE; } return $this->has_exposed; } /** * {@inheritdoc} */ public function displaysExposed() { return TRUE; } /** * {@inheritdoc} */ public function usesAJAX() { return $this->usesAJAX; } /** * {@inheritdoc} */ public function ajaxEnabled() { if ($this->usesAJAX()) { return $this->getOption('use_ajax'); } return FALSE; } /** * {@inheritdoc} */ public function isEnabled() { return (bool) $this->getOption('enabled'); } /** * {@inheritdoc} */ public function usesPager() { return $this->usesPager; } /** * {@inheritdoc} */ public function isPagerEnabled() { if ($this->usesPager()) { $pager = $this->getPlugin('pager'); if ($pager) { return $pager->usePager(); } } return FALSE; } /** * {@inheritdoc} */ public function usesMore() { return $this->usesMore; } /** * {@inheritdoc} */ public function isMoreEnabled() { if ($this->usesMore()) { return $this->getOption('use_more'); } return FALSE; } /** * {@inheritdoc} */ public function useGroupBy() { return $this->getOption('group_by'); } /** * {@inheritdoc} */ public function useMoreAlways() { if ($this->usesMore()) { return $this->getOption('use_more_always'); } return FALSE; } /** * {@inheritdoc} */ public function useMoreText() { if ($this->usesMore()) { return $this->getOption('use_more_text'); } return FALSE; } /** * {@inheritdoc} */ public function acceptAttachments() { // To be able to accept attachments this display have to be able to use // attachments but at the same time, you cannot attach a display to itself. if (!$this->usesAttachments() || ($this->definition['id'] == $this->view->current_display)) { return FALSE; } if (!empty($this->view->argument) && $this->getOption('hide_attachment_summary')) { foreach ($this->view->argument as $argument) { if ($argument->needsStylePlugin() && empty($argument->argument_validated)) { return FALSE; } } } return TRUE; } /** * {@inheritdoc} */ public function usesAttachments() { return $this->usesAttachments; } /** * {@inheritdoc} */ public function usesAreas() { return $this->usesAreas; } /** * {@inheritdoc} */ public function attachTo(ViewExecutable $view, $display_id, array &$build) {} /** * {@inheritdoc} */ public function defaultableSections($section = NULL) { $sections = [ 'access' => ['access'], 'cache' => ['cache'], 'title' => ['title'], 'css_class' => ['css_class'], 'use_ajax' => ['use_ajax'], 'hide_attachment_summary' => ['hide_attachment_summary'], 'show_admin_links' => ['show_admin_links'], 'group_by' => ['group_by'], 'query' => ['query'], 'use_more' => ['use_more', 'use_more_always', 'use_more_text'], 'use_more_always' => ['use_more', 'use_more_always', 'use_more_text'], 'use_more_text' => ['use_more', 'use_more_always', 'use_more_text'], 'link_display' => ['link_display', 'link_url'], // Force these to cascade properly. 'style' => ['style', 'row'], 'row' => ['style', 'row'], 'pager' => ['pager'], 'exposed_form' => ['exposed_form'], // These sections are special. 'header' => ['header'], 'footer' => ['footer'], 'empty' => ['empty'], 'relationships' => ['relationships'], 'fields' => ['fields'], 'sorts' => ['sorts'], 'arguments' => ['arguments'], 'filters' => ['filters', 'filter_groups'], 'filter_groups' => ['filters', 'filter_groups'], ]; // If the display cannot use a pager, then we cannot default it. if (!$this->usesPager()) { unset($sections['pager']); unset($sections['items_per_page']); } foreach ($this->extenders as $extender) { $extender->defaultableSections($sections, $section); } if ($section) { if (!empty($sections[$section])) { return $sections[$section]; } } else { return $sections; } } protected function defineOptions() { $options = [ 'defaults' => [ 'default' => [ 'access' => TRUE, 'cache' => TRUE, 'query' => TRUE, 'title' => TRUE, 'css_class' => TRUE, 'display_description' => FALSE, 'use_ajax' => TRUE, 'hide_attachment_summary' => TRUE, 'show_admin_links' => TRUE, 'pager' => TRUE, 'use_more' => TRUE, 'use_more_always' => TRUE, 'use_more_text' => TRUE, 'exposed_form' => TRUE, 'link_display' => TRUE, 'link_url' => TRUE, 'group_by' => TRUE, 'style' => TRUE, 'row' => TRUE, 'header' => TRUE, 'footer' => TRUE, 'empty' => TRUE, 'relationships' => TRUE, 'fields' => TRUE, 'sorts' => TRUE, 'arguments' => TRUE, 'filters' => TRUE, 'filter_groups' => TRUE, ], ], 'title' => [ 'default' => '', ], 'enabled' => [ 'default' => TRUE, ], 'display_comment' => [ 'default' => '', ], 'css_class' => [ 'default' => '', ], 'display_description' => [ 'default' => '', ], 'use_ajax' => [ 'default' => FALSE, ], 'hide_attachment_summary' => [ 'default' => FALSE, ], 'show_admin_links' => [ 'default' => TRUE, ], 'use_more' => [ 'default' => FALSE, ], 'use_more_always' => [ 'default' => TRUE, ], 'use_more_text' => [ 'default' => 'more', ], 'link_display' => [ 'default' => '', ], 'link_url' => [ 'default' => '', ], 'group_by' => [ 'default' => FALSE, ], 'rendering_language' => [ 'default' => '***LANGUAGE_entity_translation***', ], // These types are all plugins that can have individual settings // and therefore need special handling. 'access' => [ 'contains' => [ 'type' => ['default' => 'none'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'cache' => [ 'contains' => [ 'type' => ['default' => 'tag'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'query' => [ 'contains' => [ 'type' => ['default' => 'views_query'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'exposed_form' => [ 'contains' => [ 'type' => ['default' => 'basic'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'pager' => [ 'contains' => [ 'type' => ['default' => 'mini'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'style' => [ 'contains' => [ 'type' => ['default' => 'default'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'row' => [ 'contains' => [ 'type' => ['default' => 'fields'], 'options' => ['default' => []], ], 'merge_defaults' => [$this, 'mergePlugin'], ], 'exposed_block' => [ 'default' => FALSE, ], 'header' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'footer' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'empty' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], // We want these to export last. // These are the 5 handler types. 'relationships' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'fields' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'sorts' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'arguments' => [ 'default' => [], 'merge_defaults' => [$this, 'mergeHandler'], ], 'filter_groups' => [ 'contains' => [ 'operator' => ['default' => 'AND'], 'groups' => ['default' => [1 => 'AND']], ], ], 'filters' => [ 'default' => [], ], ]; if (!$this->usesPager()) { $options['defaults']['default']['pager'] = FALSE; $options['pager']['contains']['type']['default'] = 'some'; } if ($this->isDefaultDisplay()) { unset($options['defaults']); } $options['display_extenders'] = ['default' => []]; // First allow display extenders to provide new options. foreach ($this->extenders as $extender_id => $extender) { $options['display_extenders']['contains'][$extender_id]['contains'] = $extender->defineOptions(); } // Then allow display extenders to alter existing default values. foreach ($this->extenders as $extender) { $extender->defineOptionsAlter($options); } return $options; } /** * {@inheritdoc} */ public function hasPath() { return FALSE; } /** * {@inheritdoc} */ public function usesLinkDisplay() { return !$this->hasPath(); } /** * {@inheritdoc} */ public function usesExposedFormInBlock() { return $this->hasPath(); } /** * {@inheritdoc} */ public function getAttachedDisplays() { $current_display_id = $this->display['id']; $attached_displays = []; // Go through all displays and search displays which link to this one. foreach ($this->view->storage->get('display') as $display_id => $display) { if (isset($display['display_options']['displays'])) { $displays = $display['display_options']['displays']; if (isset($displays[$current_display_id])) { $attached_displays[] = $display_id; } } } return $attached_displays; } /** * {@inheritdoc} */ public function getLinkDisplay() { $display_id = $this->getOption('link_display'); // If unknown, pick the first one. if (empty($display_id) || !$this->view->displayHandlers->has($display_id)) { foreach ($this->view->displayHandlers as $display_id => $display) { if (!empty($display) && $display->hasPath()) { return $display_id; } } } else { return $display_id; } // Fall-through returns NULL. } /** * {@inheritdoc} */ public function getPath() { if ($this->hasPath()) { return $this->getOption('path'); } $display_id = $this->getLinkDisplay(); if ($display_id && $this->view->displayHandlers->has($display_id) && is_object($this->view->displayHandlers->get($display_id))) { return $this->view->displayHandlers->get($display_id)->getPath(); } } /** * {@inheritdoc} */ public function getRoutedDisplay() { // If this display has a route, return this display. if ($this instanceof DisplayRouterInterface) { return $this; } // If the display does not have a route (e.g. a block display), get the // route for the linked display. $display_id = $this->getLinkDisplay(); if ($display_id && $this->view->displayHandlers->has($display_id) && is_object($this->view->displayHandlers->get($display_id))) { return $this->view->displayHandlers->get($display_id)->getRoutedDisplay(); } // No routed display exists, so return NULL return NULL; } /** * {@inheritdoc} */ public function getUrl() { return $this->view->getUrl(NULL, $this->display['id']); } /** * {@inheritdoc} */ public function isDefaulted($option) { return !$this->isDefaultDisplay() && !empty($this->default_display) && !empty($this->options['defaults'][$option]); } /** * {@inheritdoc} */ public function getOption($option) { if ($this->isDefaulted($option)) { return $this->default_display->getOption($option); } if (isset($this->options[$option]) || array_key_exists($option, $this->options)) { return $this->options[$option]; } } /** * {@inheritdoc} */ public function usesFields() { return $this->getPlugin('style')->usesFields(); } /** * {@inheritdoc} */ public function getPlugin($type) { // Look up the plugin name to use for this instance. $options = $this->getOption($type); // Return now if no options have been loaded. if (empty($options) || !isset($options['type'])) { return; } // Query plugins allow specifying a specific query class per base table. if ($type == 'query') { $views_data = Views::viewsData()->get($this->view->storage->get('base_table')); $name = isset($views_data['table']['base']['query_id']) ? $views_data['table']['base']['query_id'] : 'views_query'; } else { $name = $options['type']; } // Plugin instances are stored on the display for re-use. if (!isset($this->plugins[$type][$name])) { $plugin = Views::pluginManager($type)->createInstance($name); // Initialize the plugin. $plugin->init($this->view, $this, $options['options']); $this->plugins[$type][$name] = $plugin; } return $this->plugins[$type][$name]; } /** * {@inheritdoc} */ public function &getHandler($type, $id) { if (!isset($this->handlers[$type])) { $this->getHandlers($type); } if (isset($this->handlers[$type][$id])) { return $this->handlers[$type][$id]; } // So we can return a reference. $null = NULL; return $null; } /** * {@inheritdoc} */ public function &getHandlers($type) { if (!isset($this->handlers[$type])) { $this->handlers[$type] = []; $types = ViewExecutable::getHandlerTypes(); $plural = $types[$type]['plural']; // Cast to an array so that if the display does not have any handlers of // this type there is no PHP error. foreach ((array) $this->getOption($plural) as $id => $info) { // If this is during form submission and there are temporary options // which can only appear if the view is in the edit cache, use those // options instead. This is used for AJAX multi-step stuff. if ($this->view->getRequest()->request->get('form_id') && isset($this->view->temporary_options[$type][$id])) { $info = $this->view->temporary_options[$type][$id]; } if ($info['id'] != $id) { $info['id'] = $id; } // If aggregation is on, the group type might override the actual // handler that is in use. This piece of code checks that and, // if necessary, sets the override handler. $override = NULL; if ($this->useGroupBy() && !empty($info['group_type'])) { if (empty($this->view->query)) { $this->view->initQuery(); } $aggregate = $this->view->query->getAggregationInfo(); if (!empty($aggregate[$info['group_type']]['handler'][$type])) { $override = $aggregate[$info['group_type']]['handler'][$type]; } } if (!empty($types[$type]['type'])) { $handler_type = $types[$type]['type']; } else { $handler_type = $type; } if ($handler = Views::handlerManager($handler_type)->getHandler($info, $override)) { // Special override for area types so they know where they come from. if ($handler instanceof AreaPluginBase) { $handler->areaType = $type; } $handler->init($this->view, $this, $info); $this->handlers[$type][$id] = &$handler; } // Prevent reference problems. unset($handler); } } return $this->handlers[$type]; } /** * Gets all the handlers used by the display. * * @param bool $only_overrides * Whether to include only overridden handlers. * * @return \Drupal\views\Plugin\views\ViewsHandlerInterface[] */ protected function getAllHandlers($only_overrides = FALSE) { $handler_types = Views::getHandlerTypes(); $handlers = []; // Collect all dependencies of all handlers. foreach ($handler_types as $handler_type => $handler_type_info) { if ($only_overrides && $this->isDefaulted($handler_type_info['plural'])) { continue; } $handlers = array_merge($handlers, array_values($this->getHandlers($handler_type))); } return $handlers; } /** * Gets all the plugins used by the display. * * @param bool $only_overrides * Whether to include only overridden plugins. * * @return \Drupal\views\Plugin\views\ViewsPluginInterface[] */ protected function getAllPlugins($only_overrides = FALSE) { $plugins = []; // Collect all dependencies of plugins. foreach (Views::getPluginTypes('plugin') as $plugin_type) { $plugin = $this->getPlugin($plugin_type); if (!$plugin) { continue; } if ($only_overrides && $this->isDefaulted($plugin_type)) { continue; } $plugins[] = $plugin; } return $plugins; } /** * {@inheritdoc} */ public function calculateDependencies() { $this->dependencies = parent::calculateDependencies(); // Collect all the dependencies of handlers and plugins. Only calculate // their dependencies if they are configured by this display. $plugins = array_merge($this->getAllHandlers(TRUE), $this->getAllPlugins(TRUE)); array_walk($plugins, [$this, 'calculatePluginDependencies']); return $this->dependencies; } /** * {@inheritdoc} */ public function getFieldLabels($groupable_only = FALSE) { $options = []; foreach ($this->getHandlers('relationship') as $relationship => $handler) { $relationships[$relationship] = $handler->adminLabel(); } foreach ($this->getHandlers('field') as $id => $handler) { if ($groupable_only && !$handler->useStringGroupBy()) { // Continue to next handler if it's not groupable. continue; } if ($label = $handler->label()) { $options[$id] = $label; } else { $options[$id] = $handler->adminLabel(); } if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) { $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id]; } } return $options; } /** * {@inheritdoc} */ public function setOption($option, $value) { if ($this->isDefaulted($option)) { return $this->default_display->setOption($option, $value); } // Set this in two places: On the handler where we'll notice it // but also on the display object so it gets saved. This should // only be a temporary fix. $this->display['display_options'][$option] = $value; return $this->options[$option] = $value; } /** * {@inheritdoc} */ public function overrideOption($option, $value) { $this->setOverride($option, FALSE); $this->setOption($option, $value); } /** * {@inheritdoc} */ public function optionLink($text, $section, $class = '', $title = '') { if (!trim($text)) { $text = $this->t('Broken field'); } if (!empty($class)) { $text = new FormattableMarkup('@text', ['@text' => $text]); } if (empty($title)) { $title = $text; } return \Drupal::l($text, new Url('views_ui.form_display', [ 'js' => 'nojs', 'view' => $this->view->storage->id(), 'display_id' => $this->display['id'], 'type' => $section, ], [ 'attributes' => [ 'class' => ['views-ajax-link', $class], 'title' => $title, 'id' => Html::getUniqueId('views-' . $this->display['id'] . '-' . $section), ], ])); } /** * {@inheritdoc} */ public function getArgumentsTokens() { $tokens = []; if (!empty($this->view->build_info['substitutions'])) { $tokens = $this->view->build_info['substitutions']; } return $tokens; } /** * {@inheritdoc} */ public function optionsSummary(&$categories, &$options) { $categories = [ 'title' => [ 'title' => $this->t('Title'), 'column' => 'first', ], 'format' => [ 'title' => $this->t('Format'), 'column' => 'first', ], 'filters' => [ 'title' => $this->t('Filters'), 'column' => 'first', ], 'fields' => [ 'title' => $this->t('Fields'), 'column' => 'first', ], 'pager' => [ 'title' => $this->t('Pager'), 'column' => 'second', ], 'language' => [ 'title' => $this->t('Language'), 'column' => 'second', ], 'exposed' => [ 'title' => $this->t('Exposed form'), 'column' => 'third', 'build' => [ '#weight' => 1, ], ], 'access' => [ 'title' => '', 'column' => 'second', 'build' => [ '#weight' => -5, ], ], 'other' => [ 'title' => $this->t('Other'), 'column' => 'third', 'build' => [ '#weight' => 2, ], ], ]; if ($this->display['id'] != 'default') { $options['display_id'] = [ 'category' => 'other', 'title' => $this->t('Machine Name'), 'value' => !empty($this->display['new_id']) ? $this->display['new_id'] : $this->display['id'], 'desc' => $this->t('Change the machine name of this display.'), ]; } $display_comment = views_ui_truncate($this->getOption('display_comment'), 80); $options['display_comment'] = [ 'category' => 'other', 'title' => $this->t('Administrative comment'), 'value' => !empty($display_comment) ? $display_comment : $this->t('None'), 'desc' => $this->t('Comment or document this display.'), ]; $title = strip_tags($this->getOption('title')); if (!$title) { $title = $this->t('None'); } $options['title'] = [ 'category' => 'title', 'title' => $this->t('Title'), 'value' => views_ui_truncate($title, 32), 'desc' => $this->t('Change the title that this display will use.'), ]; $style_plugin_instance = $this->getPlugin('style'); $style_summary = empty($style_plugin_instance->definition['title']) ? $this->t('Missing style plugin') : $style_plugin_instance->summaryTitle(); $style_title = empty($style_plugin_instance->definition['title']) ? $this->t('Missing style plugin') : $style_plugin_instance->pluginTitle(); $options['style'] = [ 'category' => 'format', 'title' => $this->t('Format'), 'value' => $style_title, 'setting' => $style_summary, 'desc' => $this->t('Change the way content is formatted.'), ]; // This adds a 'Settings' link to the style_options setting if the style has // options. if ($style_plugin_instance->usesOptions()) { $options['style']['links']['style_options'] = $this->t('Change settings for this format'); } if ($style_plugin_instance->usesRowPlugin()) { $row_plugin_instance = $this->getPlugin('row'); $row_summary = empty($row_plugin_instance->definition['title']) ? $this->t('Missing row plugin') : $row_plugin_instance->summaryTitle(); $row_title = empty($row_plugin_instance->definition['title']) ? $this->t('Missing row plugin') : $row_plugin_instance->pluginTitle(); $options['row'] = [ 'category' => 'format', 'title' => $this->t('Show'), 'value' => $row_title, 'setting' => $row_summary, 'desc' => $this->t('Change the way each row in the view is styled.'), ]; // This adds a 'Settings' link to the row_options setting if the row style // has options. if ($row_plugin_instance->usesOptions()) { $options['row']['links']['row_options'] = $this->t('Change settings for this style'); } } if ($this->usesAJAX()) { $options['use_ajax'] = [ 'category' => 'other', 'title' => $this->t('Use AJAX'), 'value' => $this->getOption('use_ajax') ? $this->t('Yes') : $this->t('No'), 'desc' => $this->t('Change whether or not this display will use AJAX.'), ]; } if ($this->usesAttachments()) { $options['hide_attachment_summary'] = [ 'category' => 'other', 'title' => $this->t('Hide attachments in summary'), 'value' => $this->getOption('hide_attachment_summary') ? $this->t('Yes') : $this->t('No'), 'desc' => $this->t('Change whether or not to display attachments when displaying a contextual filter summary.'), ]; } if (!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])) { $options['show_admin_links'] = [ 'category' => 'other', 'title' => $this->t('Contextual links'), 'value' => $this->getOption('show_admin_links') ? $this->t('Shown') : $this->t('Hidden'), 'desc' => $this->t('Change whether or not to display contextual links for this view.'), ]; } $pager_plugin = $this->getPlugin('pager'); if (!$pager_plugin) { // Default to the no pager plugin. $pager_plugin = Views::pluginManager('pager')->createInstance('none'); } $pager_str = $pager_plugin->summaryTitle(); $options['pager'] = [ 'category' => 'pager', 'title' => $this->t('Use pager'), 'value' => $pager_plugin->pluginTitle(), 'setting' => $pager_str, 'desc' => $this->t("Change this display's pager setting."), ]; // If pagers aren't allowed, change the text of the item. if (!$this->usesPager()) { $options['pager']['title'] = $this->t('Items to display'); } if ($pager_plugin->usesOptions()) { $options['pager']['links']['pager_options'] = $this->t('Change settings for this pager type.'); } if ($this->usesMore()) { $options['use_more'] = [ 'category' => 'pager', 'title' => $this->t('More link'), 'value' => $this->getOption('use_more') ? $this->t('Yes') : $this->t('No'), 'desc' => $this->t('Specify whether this display will provide a "more" link.'), ]; } $this->view->initQuery(); if ($this->view->query->getAggregationInfo()) { $options['group_by'] = [ 'category' => 'other', 'title' => $this->t('Use aggregation'), 'value' => $this->getOption('group_by') ? $this->t('Yes') : $this->t('No'), 'desc' => $this->t('Allow grouping and aggregation (calculation) of fields.'), ]; } $options['query'] = [ 'category' => 'other', 'title' => $this->t('Query settings'), 'value' => $this->t('Settings'), 'desc' => $this->t('Allow to set some advanced settings for the query plugin'), ]; if (\Drupal::languageManager()->isMultilingual() && $this->isBaseTableTranslatable()) { $rendering_language_options = $this->buildRenderingLanguageOptions(); $options['rendering_language'] = [ 'category' => 'language', 'title' => $this->t('Rendering Language'), 'value' => $rendering_language_options[$this->getOption('rendering_language')], 'desc' => $this->t('All content that supports translations will be displayed in the selected language.'), ]; } $access_plugin = $this->getPlugin('access'); if (!$access_plugin) { // Default to the no access control plugin. $access_plugin = Views::pluginManager('access')->createInstance('none'); } $access_str = $access_plugin->summaryTitle(); $options['access'] = [ 'category' => 'access', 'title' => $this->t('Access'), 'value' => $access_plugin->pluginTitle(), 'setting' => $access_str, 'desc' => $this->t('Specify access control type for this display.'), ]; if ($access_plugin->usesOptions()) { $options['access']['links']['access_options'] = $this->t('Change settings for this access type.'); } $cache_plugin = $this->getPlugin('cache'); if (!$cache_plugin) { // Default to the no cache control plugin. $cache_plugin = Views::pluginManager('cache')->createInstance('none'); } $cache_str = $cache_plugin->summaryTitle(); $options['cache'] = [ 'category' => 'other', 'title' => $this->t('Caching'), 'value' => $cache_plugin->pluginTitle(), 'setting' => $cache_str, 'desc' => $this->t('Specify caching type for this display.'), ]; if ($cache_plugin->usesOptions()) { $options['cache']['links']['cache_options'] = $this->t('Change settings for this caching type.'); } if ($access_plugin->usesOptions()) { $options['access']['links']['access_options'] = $this->t('Change settings for this access type.'); } if ($this->usesLinkDisplay()) { $link_display_option = $this->getOption('link_display'); $link_display = $this->t('None'); if ($link_display_option == 'custom_url') { $link_display = $this->t('Custom URL'); } elseif (!empty($link_display_option)) { $display_id = $this->getLinkDisplay(); $displays = $this->view->storage->get('display'); if (!empty($displays[$display_id])) { $link_display = $displays[$display_id]['display_title']; } } $options['link_display'] = [ 'category' => 'pager', 'title' => $this->t('Link display'), 'value' => $link_display, 'desc' => $this->t('Specify which display or custom URL this display will link to.'), ]; } if ($this->usesExposedFormInBlock()) { $options['exposed_block'] = [ 'category' => 'exposed', 'title' => $this->t('Exposed form in block'), 'value' => $this->getOption('exposed_block') ? $this->t('Yes') : $this->t('No'), 'desc' => $this->t('Allow the exposed form to appear in a block instead of the view.'), ]; } /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ $exposed_form_plugin = $this->getPlugin('exposed_form'); if (!$exposed_form_plugin) { // Default to the no cache control plugin. $exposed_form_plugin = Views::pluginManager('exposed_form')->createInstance('basic'); } $exposed_form_str = $exposed_form_plugin->summaryTitle(); $options['exposed_form'] = [ 'category' => 'exposed', 'title' => $this->t('Exposed form style'), 'value' => $exposed_form_plugin->pluginTitle(), 'setting' => $exposed_form_str, 'desc' => $this->t('Select the kind of exposed filter to use.'), ]; if ($exposed_form_plugin->usesOptions()) { $options['exposed_form']['links']['exposed_form_options'] = $this->t('Exposed form settings for this exposed form style.'); } $css_class = trim($this->getOption('css_class')); if (!$css_class) { $css_class = $this->t('None'); } $options['css_class'] = [ 'category' => 'other', 'title' => $this->t('CSS class'), 'value' => $css_class, 'desc' => $this->t('Change the CSS class name(s) that will be added to this display.'), ]; foreach ($this->extenders as $extender) { $extender->optionsSummary($categories, $options); } } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $section = $form_state->get('section'); if ($this->defaultableSections($section)) { views_ui_standard_display_dropdown($form, $form_state, $section); } $form['#title'] = $this->display['display_title'] . ': '; // Set the 'section' to highlight on the form. // If it's the item we're looking at is pulling from the default display, // reflect that. Don't use is_defaulted since we want it to show up even // on the default display. if (!empty($this->options['defaults'][$section])) { $form['#section'] = 'default-' . $section; } else { $form['#section'] = $this->display['id'] . '-' . $section; } switch ($section) { case 'display_id': $form['#title'] .= $this->t('The machine name of this display'); $form['display_id'] = [ '#type' => 'textfield', '#title' => $this->t('Machine name of the display'), '#default_value' => !empty($this->display['new_id']) ? $this->display['new_id'] : $this->display['id'], '#required' => TRUE, '#size' => 64, ]; break; case 'display_title': $form['#title'] .= $this->t('The name and the description of this display'); $form['display_title'] = [ '#title' => $this->t('Administrative name'), '#type' => 'textfield', '#default_value' => $this->display['display_title'], ]; $form['display_description'] = [ '#title' => $this->t('Administrative description'), '#type' => 'textfield', '#default_value' => $this->getOption('display_description'), ]; break; case 'display_comment': $form['#title'] .= $this->t('Administrative comment'); $form['display_comment'] = [ '#type' => 'textarea', '#title' => $this->t('Administrative comment'), '#description' => $this->t('This description will only be seen within the administrative interface and can be used to document this display.'), '#default_value' => $this->getOption('display_comment'), ]; break; case 'title': $form['#title'] .= $this->t('The title of this view'); $form['title'] = [ '#title' => $this->t('Title'), '#type' => 'textfield', '#description' => $this->t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'), '#default_value' => $this->getOption('title'), '#maxlength' => 255, ]; break; case 'css_class': $form['#title'] .= $this->t('CSS class'); $form['css_class'] = [ '#type' => 'textfield', '#title' => $this->t('CSS class name(s)'), '#description' => $this->t('Separate multiple classes by spaces.'), '#default_value' => $this->getOption('css_class'), ]; break; case 'use_ajax': $form['#title'] .= $this->t('AJAX'); $form['use_ajax'] = [ '#description' => $this->t('Options such as paging, table sorting, and exposed filters will not initiate a page refresh.'), '#type' => 'checkbox', '#title' => $this->t('Use AJAX'), '#default_value' => $this->getOption('use_ajax') ? 1 : 0, ]; break; case 'hide_attachment_summary': $form['#title'] .= $this->t('Hide attachments when displaying a contextual filter summary'); $form['hide_attachment_summary'] = [ '#type' => 'checkbox', '#title' => $this->t('Hide attachments in summary'), '#default_value' => $this->getOption('hide_attachment_summary') ? 1 : 0, ]; break; case 'show_admin_links': $form['#title'] .= $this->t('Show contextual links on this view.'); $form['show_admin_links'] = [ '#type' => 'checkbox', '#title' => $this->t('Show contextual links'), '#default_value' => $this->getOption('show_admin_links'), ]; break; case 'use_more': $form['#title'] .= $this->t('Add a more link to the bottom of the display.'); $form['use_more'] = [ '#type' => 'checkbox', '#title' => $this->t('Create more link'), '#description' => $this->t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' section under pager. You can override the URL at the link display setting."), '#default_value' => $this->getOption('use_more'), ]; $form['use_more_always'] = [ '#type' => 'checkbox', '#title' => $this->t('Always display the more link'), '#description' => $this->t('Check this to display the more link even if there are no more items to display.'), '#default_value' => $this->getOption('use_more_always'), '#states' => [ 'visible' => [ ':input[name="use_more"]' => ['checked' => TRUE], ], ], ]; $form['use_more_text'] = [ '#type' => 'textfield', '#title' => $this->t('More link text'), '#description' => $this->t('The text to display for the more link.'), '#default_value' => $this->getOption('use_more_text'), '#states' => [ 'visible' => [ ':input[name="use_more"]' => ['checked' => TRUE], ], ], ]; break; case 'group_by': $form['#title'] .= $this->t('Allow grouping and aggregation (calculation) of fields.'); $form['group_by'] = [ '#type' => 'checkbox', '#title' => $this->t('Aggregate'), '#description' => $this->t('If enabled, some fields may become unavailable. All fields that are selected for grouping will be collapsed to one record per distinct value. Other fields which are selected for aggregation will have the function run on them. For example, you can group nodes on title and count the number of nids in order to get a list of duplicate titles.'), '#default_value' => $this->getOption('group_by'), ]; break; case 'access': $form['#title'] .= $this->t('Access restrictions'); $form['access'] = [ '#prefix' => '
', '#markup' => $this->t('The following tokens are available for this link. You may use Twig syntax in this field.'), '#suffix' => '
', ]; foreach (array_keys($options) as $type) { if (!empty($options[$type])) { $items = []; foreach ($options[$type] as $key => $value) { $items[] = $key . ' == ' . $value; } $item_list = [ '#theme' => 'item_list', '#items' => $items, ]; $description[] = $item_list; } } } $form['link_url'] = [ '#type' => 'textfield', '#title' => $this->t('Custom URL'), '#default_value' => $this->getOption('link_url'), '#description' => $description, '#states' => [ 'visible' => [ ':input[name="link_display"]' => ['value' => 'custom_url'], ], ], ]; break; case 'exposed_block': $form['#title'] .= $this->t('Put the exposed form in a block'); $form['description'] = [ '#markup' => '