function WizardPluginBase::defaultDisplayOptions

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions()
  2. 8.9.x core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions()
  3. 11.x core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions()

Assembles the default display options for the view.

Most wizards will need to override this method to provide some fields or a different row plugin.

Return value

array Returns an array of display options.

10 calls to WizardPluginBase::defaultDisplayOptions()
Comment::defaultDisplayOptions in core/modules/comment/src/Plugin/views/wizard/Comment.php
Assembles the default display options for the view.
File::defaultDisplayOptions in core/modules/file/src/Plugin/views/wizard/File.php
Assembles the default display options for the view.
Media::defaultDisplayOptions in core/modules/media/src/Plugin/views/wizard/Media.php
Assembles the default display options for the view.
MediaRevision::defaultDisplayOptions in core/modules/media/src/Plugin/views/wizard/MediaRevision.php
Assembles the default display options for the view.
Node::defaultDisplayOptions in core/modules/node/src/Plugin/views/wizard/Node.php
Assembles the default display options for the view.

... See full list

9 methods override WizardPluginBase::defaultDisplayOptions()
Comment::defaultDisplayOptions in core/modules/comment/src/Plugin/views/wizard/Comment.php
Assembles the default display options for the view.
File::defaultDisplayOptions in core/modules/file/src/Plugin/views/wizard/File.php
Assembles the default display options for the view.
Media::defaultDisplayOptions in core/modules/media/src/Plugin/views/wizard/Media.php
Assembles the default display options for the view.
MediaRevision::defaultDisplayOptions in core/modules/media/src/Plugin/views/wizard/MediaRevision.php
Assembles the default display options for the view.
Node::defaultDisplayOptions in core/modules/node/src/Plugin/views/wizard/Node.php
Assembles the default display options for the view.

... See full list

File

core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php, line 831

Class

WizardPluginBase
Base class for Views wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function defaultDisplayOptions() {
    $display_options = [];
    $display_options['access']['type'] = 'none';
    $display_options['cache']['type'] = 'tag';
    $display_options['query']['type'] = 'views_query';
    $display_options['exposed_form']['type'] = 'basic';
    $display_options['pager']['type'] = 'mini';
    $display_options['style']['type'] = 'default';
    $display_options['row']['type'] = 'fields';
    // Add default options array to each plugin type.
    foreach ($display_options as &$options) {
        $options['options'] = [];
    }
    // Add a least one field so the view validates and the user has a preview.
    // The base field can provide a default in its base settings; otherwise,
    // choose the first field with a field handler.
    $default_table = $this->base_table;
    $data = Views::viewsData()->get($default_table);
    if (isset($data['table']['base']['defaults']['field'])) {
        $default_field = $data['table']['base']['defaults']['field'];
        // If the table for the default field is different to the base table,
        // load the view table data for this table.
        if (isset($data['table']['base']['defaults']['table']) && $data['table']['base']['defaults']['table'] != $default_table) {
            $default_table = $data['table']['base']['defaults']['table'];
            $data = Views::viewsData()->get($default_table);
        }
    }
    else {
        foreach ($data as $default_field => $field_data) {
            if (isset($field_data['field']['id'])) {
                break;
            }
        }
    }
    // @todo Refactor the code to use ViewExecutable::addHandler. See
    //   https://www.drupal.org/node/2383157.
    $display_options['fields'][$default_field] = [
        'table' => $default_table,
        'field' => $default_field,
        'id' => $default_field,
        'entity_type' => $data[$default_field]['entity type'] ?? NULL,
        'entity_field' => $data[$default_field]['entity field'] ?? NULL,
        'plugin_id' => $data[$default_field]['field']['id'],
    ];
    return $display_options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.