class Node

Tests creating node views with the wizard.

Plugin annotation


@Plugin(
  id = "node",
  module = "node",
  base_table = "node",
  title = @Translation("Content")
)

Hierarchy

Expanded class hierarchy of Node

47 string references to 'Node'
comment_token_info in drupal/core/modules/comment/comment.tokens.inc
Implements hook_token_info().
field_views_field_default_views_data in drupal/core/modules/field/field.views.inc
Default views data implementation for a field.
file_field_views_data_views_data_alter in drupal/core/modules/file/file.views.inc
Implements hook_field_views_data_views_data_alter().
forum_views_data in drupal/core/modules/forum/forum.views.inc
Implements hook_views_data().
image_field_views_data_views_data_alter in drupal/core/modules/image/image.views.inc
Implements hook_field_views_data_views_data_alter().

... See full list

File

drupal/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php, line 29
Definition of Drupal\node\Plugin\views\wizard\Node.

Namespace

Drupal\node\Plugin\views\wizard
View source
class Node extends WizardPluginBase {

  /**
   * Set the created column.
   */
  protected $createdColumn = 'node_field_data-created';

  /**
   * Set default values for the path field options.
   */
  protected $pathField = array(
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'exclude' => TRUE,
    'link_to_node' => FALSE,
    'alter' => array(
      'alter_text' => TRUE,
      'text' => 'node/[nid]',
    ),
  );

  /**
   * Set default values for the filters.
   */
  protected $filters = array(
    'status' => array(
      'value' => TRUE,
      'table' => 'node_field_data',
      'field' => 'status',
    ),
  );

  /**
   * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts().
   *
   * @return array
   */
  public function getAvailableSorts() {

    // You can't execute functions in properties, so override the method
    return array(
      'node_field_data-title:DESC' => t('Title'),
    );
  }

  /**
   * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::rowStyleOptions().
   */
  protected function rowStyleOptions() {
    $options = array();
    $options['teasers'] = t('teasers');
    $options['full_posts'] = t('full posts');
    $options['titles'] = t('titles');
    $options['titles_linked'] = t('titles (linked)');
    $options['fields'] = t('fields');
    return $options;
  }

  /**
   * Adds the style options to the wizard form.
   *
   * @param array $form
   *   The full wizard form array.
   * @param array $form_state
   *   The current state of the wizard form.
   * @param string $type
   *   The display ID (e.g. 'page' or 'block').
   */
  protected function buildFormStyle(array &$form, array &$form_state, $type) {
    parent::buildFormStyle($form, $form_state, $type);
    $style_form =& $form['displays'][$type]['options']['style'];

    // Some style plugins don't support row plugins so stop here if that's the
    // case.
    if (!isset($style_form['row_plugin']['#default_value'])) {
      return;
    }
    $row_plugin = $style_form['row_plugin']['#default_value'];
    switch ($row_plugin) {
      case 'full_posts':
      case 'teasers':
        $style_form['row_options']['links'] = array(
          '#type' => 'select',
          '#title_display' => 'invisible',
          '#title' => t('Should links be displayed below each node'),
          '#options' => array(
            1 => t('with links (allow users to add comments, etc.)'),
            0 => t('without links'),
          ),
          '#default_value' => 1,
        );
        $style_form['row_options']['comments'] = array(
          '#type' => 'select',
          '#title_display' => 'invisible',
          '#title' => t('Should comments be displayed below each node'),
          '#options' => array(
            1 => t('with comments'),
            0 => t('without comments'),
          ),
          '#default_value' => 0,
        );
        break;
    }
  }

  /**
   * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions().
   */
  protected function defaultDisplayOptions() {
    $display_options = parent::defaultDisplayOptions();

    // Add permission-based access control.
    $display_options['access']['type'] = 'perm';

    // 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']['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']['link_to_node'] = 1;
    return $display_options;
  }

  /**
   * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayFiltersUser().
   */
  protected function defaultDisplayFiltersUser(array $form, array &$form_state) {
    $filters = parent::defaultDisplayFiltersUser($form, $form_state);
    if (!empty($form_state['values']['show']['tagged_with']['tids'])) {
      $filters['tid'] = array(
        'id' => 'tid',
        'table' => 'taxonomy_index',
        'field' => 'tid',
        'value' => $form_state['values']['show']['tagged_with']['tids'],
        'vocabulary' => $form_state['values']['show']['tagged_with']['vocabulary'],
      );

      // If the user entered more than one valid term in the autocomplete
      // field, they probably intended both of them to be applied.
      if (count($form_state['values']['show']['tagged_with']['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, array &$form_state) {
    $display_options = parent::pageDisplayOptions($form, $form_state);
    $row_plugin = isset($form_state['values']['page']['style']['row_plugin']) ? $form_state['values']['page']['style']['row_plugin'] : NULL;
    $row_options = isset($form_state['values']['page']['style']['row_options']) ? $form_state['values']['page']['style']['row_options'] : array();
    $this
      ->display_options_row($display_options, $row_plugin, $row_options);
    return $display_options;
  }

  /**
   * {@inheritdoc}
   */
  protected function blockDisplayOptions(array $form, array &$form_state) {
    $display_options = parent::blockDisplayOptions($form, $form_state);
    $row_plugin = isset($form_state['values']['block']['style']['row_plugin']) ? $form_state['values']['block']['style']['row_plugin'] : NULL;
    $row_options = isset($form_state['values']['block']['style']['row_options']) ? $form_state['values']['block']['style']['row_options'] : array();
    $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']['build_mode'] = 'full';
        $display_options['row']['options']['links'] = !empty($row_options['links']);
        $display_options['row']['options']['comments'] = !empty($row_options['comments']);
        break;
      case 'teasers':
        $display_options['row']['type'] = 'entity:node';
        $display_options['row']['options']['build_mode'] = 'teaser';
        $display_options['row']['options']['links'] = !empty($row_options['links']);
        $display_options['row']['options']['comments'] = !empty($row_options['comments']);
        break;
      case 'titles_linked':
        $display_options['row']['type'] = 'fields';
        $display_options['field']['title']['link_to_node'] = 1;
        break;
      case 'titles':
        $display_options['row']['type'] = 'fields';
        $display_options['field']['title']['link_to_node'] = 0;
        break;
    }
  }

  /**
   * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::buildFilters().
   *
   * Add some options for filter by taxonomy terms.
   */
  protected function buildFilters(&$form, &$form_state) {
    parent::buildFilters($form, $form_state);
    $selected_bundle = static::getSelected($form_state, array(
      '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_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(entity_get_bundles($this->entity_type));

    // 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 = array(
        $selected_bundle,
      );
    }
    $tag_fields = array();
    foreach ($bundles as $bundle) {
      foreach (field_info_instances($this->entity_type, $bundle) as $instance) {
        $widget = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')
          ->getComponent($instance['field_name']);

        // We define "tag-like" taxonomy fields as ones that use the
        // "Autocomplete term widget (tagging)" widget.
        if ($widget['type'] == 'taxonomy_autocomplete') {
          $tag_fields[] = $instance['field_name'];
        }
      }
    }
    $tag_fields = array_unique($tag_fields);
    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 (in_array('field_tags', $tag_fields)) {
        $tag_field_name = 'field_tags';
      }
      else {
        $tag_field_name = reset($tag_fields);
      }

      // Add the autocomplete textfield to the wizard.
      $form['displays']['show']['tagged_with'] = array(
        '#type' => 'textfield',
        '#title' => t('tagged with'),
        '#autocomplete_path' => 'taxonomy/autocomplete/' . $tag_field_name,
        '#size' => 30,
        '#maxlength' => 1024,
        '#field_name' => $tag_field_name,
        '#element_validate' => array(
          'views_ui_taxonomy_autocomplete_validate',
        ),
      );
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerFactoryPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 11
Node::$createdColumn protected property Set the created column. Overrides WizardPluginBase::$createdColumn
Node::$filters protected property Set default values for the filters. Overrides WizardPluginBase::$filters
Node::$pathField protected property Set default values for the path field options. Overrides WizardPluginBase::$pathField
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::buildFormStyle protected function Adds the style options to the wizard form. Overrides WizardPluginBase::buildFormStyle
Node::defaultDisplayFiltersUser protected function Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayFiltersUser(). Overrides WizardPluginBase::defaultDisplayFiltersUser
Node::defaultDisplayOptions protected function Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions(). 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 Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::rowStyleOptions(). Overrides WizardPluginBase::rowStyleOptions
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$definition public property Plugins's 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::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
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. 15
PluginBase::defineOptions protected function Information about options for all kinds of purposes will be held here. @code 'option_name' => array( 14
PluginBase::destroy public function Clears a plugin. 2
PluginBase::getAvailableGlobalTokens public function Returns an array of available token replacements.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::globalTokenForm public function Adds elements for available core tokens to a form.
PluginBase::globalTokenReplace public function Returns a string with any core tokens replaced.
PluginBase::init public function Initialize the plugin. 8
PluginBase::pluginTitle public function Return the human readable name of the display.
PluginBase::query public function Add anything to the query that we might need to. 13
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. 11
PluginBase::summaryTitle public function Returns the summary of the settings in the display. 6
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. 1
PluginBase::unpackOptions public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
PluginBase::usesOptions public function Returns the usesOptions property. 8
PluginBase::validate public function Validate that the plugin is correct and can be saved. 4
PluginBase::validateOptionsForm public function Validate the options form. 11
WizardPluginBase::$availableSorts protected property The available store criteria.
WizardPluginBase::$base_table protected property The base table connected with the wizard.
WizardPluginBase::$entity_info protected property Contains the information from entity_get_info of the $entity_type.
WizardPluginBase::$entity_type protected property The entity type connected with the wizard.
WizardPluginBase::$filter_defaults protected property Default values for filters.
WizardPluginBase::$pathFieldsSupplemental protected property Additional fields required to generate the pathField. 1
WizardPluginBase::$sorts protected property Views items configuration arrays for sorts added by the wizard.
WizardPluginBase::$validated_views protected property An array of validated view objects, keyed by a hash.
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.
WizardPluginBase::buildForm public function Drupal\views\Plugin\views\wizard\WizardInterface::buildForm(). Overrides WizardInterface::buildForm
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.
WizardPluginBase::getPathField public function Gets the pathField property.
WizardPluginBase::getPathFieldsSupplemental public function Gets the pathFieldsSupplemental property.
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::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
WizardPluginBase::__construct public function Constructs a WizardPluginBase object. Overrides PluginBase::__construct