class Node

Same name in this branch
  1. 10 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node
  2. 10 core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node
  3. 10 core/modules/node/src/Plugin/views/argument_default/Node.php \Drupal\node\Plugin\views\argument_default\Node
  4. 10 core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node
  5. 10 core/modules/node/src/Plugin/migrate/source/d7/Node.php \Drupal\node\Plugin\migrate\source\d7\Node
Same name in other branches
  1. 9 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node
  2. 9 core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node
  3. 9 core/modules/node/src/Plugin/views/wizard/Node.php \Drupal\node\Plugin\views\wizard\Node
  4. 9 core/modules/node/src/Plugin/views/argument_default/Node.php \Drupal\node\Plugin\views\argument_default\Node
  5. 9 core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node
  6. 9 core/modules/node/src/Plugin/migrate/source/d7/Node.php \Drupal\node\Plugin\migrate\source\d7\Node
  7. 8.9.x core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node
  8. 8.9.x core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node
  9. 8.9.x core/modules/node/src/Plugin/views/wizard/Node.php \Drupal\node\Plugin\views\wizard\Node
  10. 8.9.x core/modules/node/src/Plugin/views/argument_default/Node.php \Drupal\node\Plugin\views\argument_default\Node
  11. 8.9.x core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node
  12. 8.9.x core/modules/node/src/Plugin/migrate/source/d7/Node.php \Drupal\node\Plugin\migrate\source\d7\Node
  13. 11.x core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node
  14. 11.x core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node
  15. 11.x core/modules/node/src/Plugin/views/wizard/Node.php \Drupal\node\Plugin\views\wizard\Node
  16. 11.x core/modules/node/src/Plugin/views/argument_default/Node.php \Drupal\node\Plugin\views\argument_default\Node
  17. 11.x core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node
  18. 11.x core/modules/node/src/Plugin/migrate/source/d7/Node.php \Drupal\node\Plugin\migrate\source\d7\Node

Tests creating node views with the wizard.

Hierarchy

Expanded class hierarchy of Node

1470 string references to 'Node'
2d3581c3-92c7-4600-8991-a0d4b3741198.yml in core/tests/fixtures/default_content/node/2d3581c3-92c7-4600-8991-a0d4b3741198.yml
core/tests/fixtures/default_content/node/2d3581c3-92c7-4600-8991-a0d4b3741198.yml
3434bd5a-d2cd-4f26-bf79-a7f6b951a21b.yml in core/tests/fixtures/default_content/menu_link_content/3434bd5a-d2cd-4f26-bf79-a7f6b951a21b.yml
core/tests/fixtures/default_content/menu_link_content/3434bd5a-d2cd-4f26-bf79-a7f6b951a21b.yml
7f1dd75a-0be2-4d3b-be5d-9d1a868b9267.yml in core/tests/fixtures/default_content/node/7f1dd75a-0be2-4d3b-be5d-9d1a868b9267.yml
core/tests/fixtures/default_content/node/7f1dd75a-0be2-4d3b-be5d-9d1a868b9267.yml
AccessPermissionTest::setUp in core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php
AddFeedTest::testFeedIconEscaping in core/modules/system/tests/src/Kernel/Common/AddFeedTest.php
Checks that special characters are correctly escaped.

... See full list

File

core/modules/node/src/Plugin/views/wizard/Node.php, line 23

Namespace

Drupal\node\Plugin\views\wizard
View source
class Node extends WizardPluginBase {
    
    /**
     * Set the created column.
     *
     * @var string
     */
    protected $createdColumn = 'node_field_data-created';
    
    /**
     * The entity display repository.
     *
     * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
     */
    protected $entityDisplayRepository;
    
    /**
     * The entity field manager.
     *
     * @var \Drupal\Core\Entity\EntityFieldManagerInterface
     */
    protected $entityFieldManager;
    
    /**
     * Node constructor.
     *
     * @param array $configuration
     *   The plugin configuration.
     * @param string $plugin_id
     *   The plugin ID.
     * @param mixed $plugin_definition
     *   The plugin definition.
     * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info_service
     *   The entity bundle info service.
     * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
     *   The entity display repository service.
     * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
     *   The entity field manager.
     * @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_form_selector
     *   The parent form selector service.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager, MenuParentFormSelectorInterface $parent_form_selector) {
        parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service, $parent_form_selector);
        $this->entityDisplayRepository = $entity_display_repository;
        $this->entityFieldManager = $entity_field_manager;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.bundle.info'), $container->get('entity_display.repository'), $container->get('entity_field.manager'), $container->get('menu.parent_form_selector'));
    }
    
    /**
     * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts().
     *
     * @return array
     *   An array whose keys are the available sort options and whose
     *   corresponding values are human readable labels.
     */
    public function getAvailableSorts() {
        // You can't execute functions in properties, so override the method
        return [
            'node_field_data-title:ASC' => $this->t('Title'),
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function rowStyleOptions() {
        $options = [];
        $options['teasers'] = $this->t('teasers');
        $options['full_posts'] = $this->t('full posts');
        $options['titles'] = $this->t('titles');
        $options['titles_linked'] = $this->t('titles (linked)');
        $options['fields'] = $this->t('fields');
        return $options;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function defaultDisplayOptions() {
        $display_options = parent::defaultDisplayOptions();
        // Add permission-based access control.
        $display_options['access']['type'] = 'perm';
        $display_options['access']['options']['perm'] = 'access content';
        // Remove the default fields, since we are customizing them here.
        unset($display_options['fields']);
        // Add the title field, so that the display has content if the user switches
        // to a row style that uses fields.
        
        /* Field: Content: Title */
        $display_options['fields']['title']['id'] = 'title';
        $display_options['fields']['title']['table'] = 'node_field_data';
        $display_options['fields']['title']['field'] = 'title';
        $display_options['fields']['title']['entity_type'] = 'node';
        $display_options['fields']['title']['entity_field'] = 'title';
        $display_options['fields']['title']['label'] = '';
        $display_options['fields']['title']['alter']['alter_text'] = 0;
        $display_options['fields']['title']['alter']['make_link'] = 0;
        $display_options['fields']['title']['alter']['absolute'] = 0;
        $display_options['fields']['title']['alter']['trim'] = 0;
        $display_options['fields']['title']['alter']['word_boundary'] = 0;
        $display_options['fields']['title']['alter']['ellipsis'] = 0;
        $display_options['fields']['title']['alter']['strip_tags'] = 0;
        $display_options['fields']['title']['alter']['html'] = 0;
        $display_options['fields']['title']['hide_empty'] = 0;
        $display_options['fields']['title']['empty_zero'] = 0;
        $display_options['fields']['title']['settings']['link_to_entity'] = 1;
        $display_options['fields']['title']['plugin_id'] = 'field';
        return $display_options;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) {
        $filters = parent::defaultDisplayFiltersUser($form, $form_state);
        $tids = [];
        if ($values = $form_state->getValue([
            'show',
            'tagged_with',
        ])) {
            foreach ($values as $value) {
                $tids[] = $value['target_id'];
            }
        }
        if (!empty($tids)) {
            $vid = reset($form['displays']['show']['tagged_with']['#selection_settings']['target_bundles']);
            $filters['tid'] = [
                'id' => 'tid',
                'table' => 'taxonomy_index',
                'field' => 'tid',
                'value' => $tids,
                'vid' => $vid,
                'plugin_id' => 'taxonomy_index_tid',
            ];
            // If the user entered more than one valid term in the autocomplete
            // field, they probably intended both of them to be applied.
            if (count($tids) > 1) {
                $filters['tid']['operator'] = 'and';
                // Sort the terms so the filter will be displayed as it normally would
                // on the edit screen.
                sort($filters['tid']['value']);
            }
        }
        return $filters;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function pageDisplayOptions(array $form, FormStateInterface $form_state) {
        $display_options = parent::pageDisplayOptions($form, $form_state);
        $row_plugin = $form_state->getValue([
            'page',
            'style',
            'row_plugin',
        ]);
        $row_options = $form_state->getValue([
            'page',
            'style',
            'row_options',
        ], []);
        $this->display_options_row($display_options, $row_plugin, $row_options);
        return $display_options;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function blockDisplayOptions(array $form, FormStateInterface $form_state) {
        $display_options = parent::blockDisplayOptions($form, $form_state);
        $row_plugin = $form_state->getValue([
            'block',
            'style',
            'row_plugin',
        ]);
        $row_options = $form_state->getValue([
            'block',
            'style',
            'row_options',
        ], []);
        $this->display_options_row($display_options, $row_plugin, $row_options);
        return $display_options;
    }
    
    /**
     * Set the row style and row style plugins to the display_options.
     */
    protected function display_options_row(&$display_options, $row_plugin, $row_options) {
        switch ($row_plugin) {
            case 'full_posts':
                $display_options['row']['type'] = 'entity:node';
                $display_options['row']['options']['view_mode'] = 'full';
                break;
            case 'teasers':
                $display_options['row']['type'] = 'entity:node';
                $display_options['row']['options']['view_mode'] = 'teaser';
                break;
            case 'titles_linked':
            case 'titles':
                $display_options['row']['type'] = 'fields';
                $display_options['fields']['title']['id'] = 'title';
                $display_options['fields']['title']['table'] = 'node_field_data';
                $display_options['fields']['title']['field'] = 'title';
                $display_options['fields']['title']['settings']['link_to_entity'] = $row_plugin === 'titles_linked';
                $display_options['fields']['title']['plugin_id'] = 'field';
                break;
        }
    }
    
    /**
     * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::buildFilters().
     *
     * Add some options for filter by taxonomy terms.
     */
    protected function buildFilters(&$form, FormStateInterface $form_state) {
        parent::buildFilters($form, $form_state);
        if (isset($form['displays']['show']['type'])) {
            $selected_bundle = static::getSelected($form_state, [
                'show',
                'type',
            ], 'all', $form['displays']['show']['type']);
        }
        // Add the "tagged with" filter to the view.
        // We construct this filter using taxonomy_index.tid (which limits the
        // filtering to a specific vocabulary) rather than
        // taxonomy_term_field_data.name (which matches terms in any vocabulary).
        // This is because it is a more commonly-used filter that works better with
        // the autocomplete UI, and also to avoid confusion with other vocabularies
        // on the site that may have terms with the same name but are not used for
        // free tagging.
        // The downside is that if there *is* more than one vocabulary on the site
        // that is used for free tagging, the wizard will only be able to make the
        // "tagged with" filter apply to one of them (see below for the method it
        // uses to choose).
        // Find all "tag-like" taxonomy fields associated with the view's
        // entities. If a particular entity type (i.e., bundle) has been
        // selected above, then we only search for taxonomy fields associated
        // with that bundle. Otherwise, we use all bundles.
        $bundles = array_keys($this->bundleInfoService
            ->getBundleInfo($this->entityTypeId));
        // Double check that this is a real bundle before using it (since above
        // we added a dummy option 'all' to the bundle list on the form).
        if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
            $bundles = [
                $selected_bundle,
            ];
        }
        $tag_fields = [];
        foreach ($bundles as $bundle) {
            $display = $this->entityDisplayRepository
                ->getFormDisplay($this->entityTypeId, $bundle);
            $taxonomy_fields = array_filter($this->entityFieldManager
                ->getFieldDefinitions($this->entityTypeId, $bundle), function (FieldDefinitionInterface $field_definition) {
                return $field_definition->getType() == 'entity_reference' && $field_definition->getSetting('target_type') == 'taxonomy_term';
            });
            foreach ($taxonomy_fields as $field_name => $field) {
                $widget = $display->getComponent($field_name);
                // We define "tag-like" taxonomy fields as ones that use the
                // "Autocomplete (Tags style)" widget.
                if (!empty($widget) && $widget['type'] == 'entity_reference_autocomplete_tags') {
                    $tag_fields[$field_name] = $field;
                }
            }
        }
        if (!empty($tag_fields)) {
            // If there is more than one "tag-like" taxonomy field available to
            // the view, we can only make our filter apply to one of them (as
            // described above). We choose 'field_tags' if it is available, since
            // that is created by the Standard install profile in core and also
            // commonly used by contrib modules; thus, it is most likely to be
            // associated with the "main" free-tagging vocabulary on the site.
            if (array_key_exists('field_tags', $tag_fields)) {
                $tag_field_name = 'field_tags';
            }
            else {
                $tag_field_name = key($tag_fields);
            }
            // Add the autocomplete textfield to the wizard.
            $form['displays']['show']['tagged_with'] = [
                '#type' => 'entity_autocomplete',
                '#title' => $this->t('tagged with'),
                '#target_type' => 'taxonomy_term',
                '#tags' => TRUE,
                '#size' => 30,
                '#maxlength' => 1024,
            ];
            $target_bundles = $tag_fields[$tag_field_name]->getSetting('handler_settings')['target_bundles'] ?? FALSE;
            if (!$target_bundles) {
                $target_bundles = array_keys($this->bundleInfoService
                    ->getBundleInfo('taxonomy_term'));
            }
            $form['displays']['show']['tagged_with']['#selection_settings']['target_bundles'] = $target_bundles;
        }
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DerivativeInspectionInterface::getBaseId public function Gets the base_plugin_id of the plugin instance. 1
DerivativeInspectionInterface::getDerivativeId public function Gets the derivative_id of the plugin instance. 1
Node::$createdColumn protected property Set the created column. Overrides WizardPluginBase::$createdColumn
Node::$entityDisplayRepository protected property The entity display repository.
Node::$entityFieldManager protected property The entity field manager.
Node::blockDisplayOptions protected function Retrieves the block display options. Overrides WizardPluginBase::blockDisplayOptions
Node::buildFilters protected function Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::buildFilters(). Overrides WizardPluginBase::buildFilters
Node::create public static function Creates an instance of the plugin. Overrides WizardPluginBase::create
Node::defaultDisplayFiltersUser protected function Retrieves filter information based on user input for the default display. Overrides WizardPluginBase::defaultDisplayFiltersUser
Node::defaultDisplayOptions protected function Assembles the default display options for the view. Overrides WizardPluginBase::defaultDisplayOptions
Node::display_options_row protected function Set the row style and row style plugins to the display_options.
Node::getAvailableSorts public function Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts(). Overrides WizardPluginBase::getAvailableSorts
Node::pageDisplayOptions protected function Retrieves the page display options. Overrides WizardPluginBase::pageDisplayOptions
Node::rowStyleOptions protected function Retrieves row style plugin names. Overrides WizardPluginBase::rowStyleOptions
Node::__construct public function Node constructor. Overrides WizardPluginBase::__construct
PluginBase::$definition public property Plugins' definition.
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$position public property The handler position.
PluginBase::$renderer protected property Stores the render API renderer. 3
PluginBase::$usesOptions protected property Denotes whether the plugin has an additional options form. 8
PluginBase::$view public property The top object of a view. 1
PluginBase::buildOptionsForm public function Provide a form to edit options for this plugin. Overrides ViewsPluginInterface::buildOptionsForm 16
PluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies 14
PluginBase::defineOptions protected function Information about options for all kinds of purposes will be held here. 18
PluginBase::destroy public function Clears a plugin. Overrides ViewsPluginInterface::destroy 2
PluginBase::doFilterByDefinedOptions protected function Do the work to filter out stored options depending on the defined options.
PluginBase::filterByDefinedOptions public function Filter out stored options depending on the defined options. Overrides ViewsPluginInterface::filterByDefinedOptions
PluginBase::getAvailableGlobalTokens public function Returns an array of available token replacements. Overrides ViewsPluginInterface::getAvailableGlobalTokens
PluginBase::getProvider public function Returns the plugin provider. Overrides ViewsPluginInterface::getProvider
PluginBase::getRenderer protected function Returns the render API renderer. 1
PluginBase::globalTokenForm public function Adds elements for available core tokens to a form. Overrides ViewsPluginInterface::globalTokenForm
PluginBase::globalTokenReplace public function Returns a string with any core tokens replaced. Overrides ViewsPluginInterface::globalTokenReplace
PluginBase::INCLUDE_ENTITY constant Include entity row languages when listing languages.
PluginBase::INCLUDE_NEGOTIATED constant Include negotiated languages when listing languages.
PluginBase::init public function Initialize the plugin. Overrides ViewsPluginInterface::init 6
PluginBase::listLanguages protected function Makes an array of languages, optionally including special languages.
PluginBase::pluginTitle public function Return the human readable name of the display. Overrides ViewsPluginInterface::pluginTitle
PluginBase::preRenderAddFieldsetMarkup public static function Moves form elements into fieldsets for presentation purposes. Overrides ViewsPluginInterface::preRenderAddFieldsetMarkup
PluginBase::preRenderFlattenData public static function Flattens the structure of form elements. Overrides ViewsPluginInterface::preRenderFlattenData
PluginBase::query public function Add anything to the query that we might need to. Overrides ViewsPluginInterface::query 8
PluginBase::queryLanguageSubstitutions public static function Returns substitutions for Views queries for languages.
PluginBase::setOptionDefaults protected function Fills up the options of the plugin with defaults.
PluginBase::submitOptionsForm public function Handle any special handling on the validate form. Overrides ViewsPluginInterface::submitOptionsForm 16
PluginBase::summaryTitle public function Returns the summary of the settings in the display. Overrides ViewsPluginInterface::summaryTitle 6
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. Overrides ViewsPluginInterface::themeFunctions 1
PluginBase::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks 6
PluginBase::unpackOptions public function Unpacks options over our existing defaults. Overrides ViewsPluginInterface::unpackOptions
PluginBase::usesOptions public function Returns the usesOptions property. Overrides ViewsPluginInterface::usesOptions 8
PluginBase::validate public function Validate that the plugin is correct and can be saved. Overrides ViewsPluginInterface::validate 6
PluginBase::validateOptionsForm public function Validate the options form. Overrides ViewsPluginInterface::validateOptionsForm 15
PluginBase::viewsTokenReplace protected function Replaces Views' tokens in a given string. 1
PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT constant Query string to indicate the site default language.
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 6
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING Deprecated constant Untrusted callbacks trigger E_USER_WARNING errors.
WizardPluginBase::$availableSorts protected property The available store criteria.
WizardPluginBase::$base_table protected property
WizardPluginBase::$bundleInfoService protected property The bundle info service.
WizardPluginBase::$entityType protected property Contains the information from entity_get_info of the $entity_type.
WizardPluginBase::$entityTypeId protected property The entity type connected with the wizard.
WizardPluginBase::$filters protected property Views items configuration arrays for filters added by the wizard. 2
WizardPluginBase::$filter_defaults protected property
WizardPluginBase::$parentFormSelector protected property The parent form selector service.
WizardPluginBase::$sorts protected property Views items configuration arrays for sorts added by the wizard.
WizardPluginBase::$validated_views protected property
WizardPluginBase::addDisplays protected function Adds the array of display options to the view, with appropriate overrides.
WizardPluginBase::alterDisplayOptions protected function Alters the full array of display options before they are added to the view.
WizardPluginBase::buildDisplayOptions protected function Builds an array of display options for the view. 1
WizardPluginBase::buildForm public function Form callback to build other elements in the "show" form. Overrides WizardInterface::buildForm
WizardPluginBase::buildFormStyle protected function Adds the style options to the wizard form.
WizardPluginBase::buildSorts protected function Builds the form structure for selecting the view's sort order.
WizardPluginBase::createView public function Creates a view from values that have already been validated. Overrides WizardInterface::createView
WizardPluginBase::defaultDisplayFilters protected function Retrieves all filter information used by the default display.
WizardPluginBase::defaultDisplaySorts protected function Retrieves all sort information used by the default display.
WizardPluginBase::defaultDisplaySortsUser protected function Retrieves sort information based on user input for the default display.
WizardPluginBase::getCreatedColumn public function Gets the createdColumn property.
WizardPluginBase::getFilters public function Gets the filters property. 1
WizardPluginBase::getSelected public static function Gets the current value of a #select element, from within a form constructor function.
WizardPluginBase::getSorts public function Gets the sorts property.
WizardPluginBase::instantiateView protected function Instantiates a view object from form values.
WizardPluginBase::pageFeedDisplayOptions protected function Retrieves the feed display options.
WizardPluginBase::restExportDisplayOptions protected function Retrieves the REST export display options from the submitted form values.
WizardPluginBase::retrieveValidatedView protected function Retrieves a validated view for a form submission.
WizardPluginBase::setDefaultOptions protected function Sets options for a display and makes them the default options if possible.
WizardPluginBase::setOverrideOptions protected function Sets options for a display, inheriting from the defaults when possible.
WizardPluginBase::setValidatedView protected function Stores a validated view from a form submission.
WizardPluginBase::validateView public function Implements Drupal\views\Plugin\views\wizard\WizardInterface::validate(). Overrides WizardInterface::validateView

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