function NodeViewsData::getViewsData

Same name and namespace in other branches
  1. 11.x core/modules/node/src/NodeViewsData.php \Drupal\node\NodeViewsData::getViewsData()
  2. 10 core/modules/node/src/NodeViewsData.php \Drupal\node\NodeViewsData::getViewsData()
  3. 9 core/modules/node/src/NodeViewsData.php \Drupal\node\NodeViewsData::getViewsData()
  4. 8.9.x core/modules/node/src/NodeViewsData.php \Drupal\node\NodeViewsData::getViewsData()

Overrides EntityViewsData::getViewsData

File

core/modules/node/src/NodeViewsData.php, line 69

Class

NodeViewsData
Provides the views data for the node entity type.

Namespace

Drupal\node

Code

public function getViewsData() {
  $data = parent::getViewsData();
  $data['node_field_data']['table']['base']['weight'] = -10;
  $data['node_field_data']['table']['base']['access query tag'] = 'node_access';
  $data['node_field_data']['table']['wizard_id'] = 'node';
  $data['node_field_data']['nid']['argument'] = [
    'id' => 'node_nid',
    'name field' => 'title',
    'numeric' => TRUE,
    'validate type' => 'nid',
  ];
  $data['node_field_data']['title']['field']['default_formatter_settings'] = [
    'link_to_entity' => TRUE,
  ];
  $data['node_field_data']['title']['field']['link_to_node default'] = TRUE;
  $data['node_field_data']['type']['argument']['id'] = 'node_type';
  $data['node_field_data']['status']['filter']['label'] = $this->t('Published status');
  $data['node_field_data']['status']['filter']['type'] = 'yes-no';
  // Use status = 1 instead of status <> 0 in WHERE statement.
  $data['node_field_data']['status']['filter']['use_equal'] = TRUE;
  // Check for any extensions that use node grants and block the use of this
  // filter. If this filter is blocked then provide a helpful message.
  $node_access_implementations = $this->getNodeAccessImplementations();
  $node_access_implementation_count = count($node_access_implementations);
  if ($node_access_implementation_count === 0) {
    $status_extra_help_text = $this->t('Filters out unpublished content if the current user cannot view it.');
  }
  else {
    uasort($node_access_implementations, 'strnatcasecmp');
    $status_extra_help_text = new PluralTranslatableMarkup($node_access_implementation_count, 'This filter has no effect because the %module module controls access.', 'This filter has no effect because these modules control access: %modules.', [
      '%module' => reset($node_access_implementations),
      '%modules' => implode(', ', $node_access_implementations),
    ]);
  }
  $data['node_field_data']['status_extra'] = [
    'title' => $this->t('Published status or admin user'),
    'help' => $status_extra_help_text,
    'filter' => [
      'field' => 'status',
      'id' => 'node_status',
      'label' => $this->t('Published status or admin user'),
    ],
  ];
  $data['node_field_data']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
  $data['node_field_data']['promote']['filter']['label'] = $this->t('Promoted to front page status');
  $data['node_field_data']['promote']['filter']['type'] = 'yes-no';
  $data['node_field_data']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
  $data['node_field_data']['sticky']['filter']['label'] = $this->t('Sticky status');
  $data['node_field_data']['sticky']['filter']['type'] = 'yes-no';
  $data['node_field_data']['sticky']['sort']['help'] = $this->t('Whether or not the content is sticky. To list sticky content first, set this to descending.');
  $data['node']['node_bulk_form'] = [
    'title' => $this->t('Node operations bulk form'),
    'help' => $this->t('Add a form element that lets you run operations on multiple nodes.'),
    'field' => [
      'id' => 'node_bulk_form',
    ],
  ];
  // Bogus fields for aliasing purposes.
  // @todo Add similar support to any date field
  // @see https://www.drupal.org/node/2337507
  $data['node_field_data']['created_fulldate'] = [
    'title' => $this->t('Created date'),
    'help' => $this->t('Date in the form of CCYYMMDD.'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_fulldate',
    ],
  ];
  $data['node_field_data']['created_year_month'] = [
    'title' => $this->t('Created year + month'),
    'help' => $this->t('Date in the form of YYYYMM.'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_year_month',
    ],
  ];
  $data['node_field_data']['created_year'] = [
    'title' => $this->t('Created year'),
    'help' => $this->t('Date in the form of YYYY.'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_year',
    ],
  ];
  $data['node_field_data']['created_month'] = [
    'title' => $this->t('Created month'),
    'help' => $this->t('Date in the form of MM (01 - 12).'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_month',
    ],
  ];
  $data['node_field_data']['created_day'] = [
    'title' => $this->t('Created day'),
    'help' => $this->t('Date in the form of DD (01 - 31).'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_day',
    ],
  ];
  $data['node_field_data']['created_week'] = [
    'title' => $this->t('Created week'),
    'help' => $this->t('Date in the form of WW (01 - 53).'),
    'argument' => [
      'field' => 'created',
      'id' => 'date_week',
    ],
  ];
  $data['node_field_data']['changed_fulldate'] = [
    'title' => $this->t('Updated date'),
    'help' => $this->t('Date in the form of CCYYMMDD.'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_fulldate',
    ],
  ];
  $data['node_field_data']['changed_year_month'] = [
    'title' => $this->t('Updated year + month'),
    'help' => $this->t('Date in the form of YYYYMM.'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_year_month',
    ],
  ];
  $data['node_field_data']['changed_year'] = [
    'title' => $this->t('Updated year'),
    'help' => $this->t('Date in the form of YYYY.'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_year',
    ],
  ];
  $data['node_field_data']['changed_month'] = [
    'title' => $this->t('Updated month'),
    'help' => $this->t('Date in the form of MM (01 - 12).'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_month',
    ],
  ];
  $data['node_field_data']['changed_day'] = [
    'title' => $this->t('Updated day'),
    'help' => $this->t('Date in the form of DD (01 - 31).'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_day',
    ],
  ];
  $data['node_field_data']['changed_week'] = [
    'title' => $this->t('Updated week'),
    'help' => $this->t('Date in the form of WW (01 - 53).'),
    'argument' => [
      'field' => 'changed',
      'id' => 'date_week',
    ],
  ];
  $data['node']['node_listing_empty'] = [
    'title' => $this->t('Empty Node Frontpage behavior'),
    'help' => $this->t('Provides a link to the node add overview page.'),
    'area' => [
      'id' => 'node_listing_empty',
    ],
  ];
  $data['node_field_data']['uid_revision']['title'] = $this->t('User has a revision');
  $data['node_field_data']['uid_revision']['help'] = $this->t('All nodes where a certain user has a revision');
  $data['node_field_data']['uid_revision']['real field'] = 'nid';
  $data['node_field_data']['uid_revision']['filter']['id'] = 'node_uid_revision';
  $data['node_field_data']['uid_revision']['argument']['id'] = 'node_uid_revision';
  $data['node_field_revision']['table']['wizard_id'] = 'node_revision';
  // Advertise this table as a possible base table.
  $data['node_field_revision']['table']['base']['help'] = $this->t('Content revision is a history of changes to content.');
  $data['node_field_revision']['table']['base']['defaults']['title'] = 'title';
  $data['node_field_revision']['nid']['argument'] = [
    'id' => 'node_nid',
    'numeric' => TRUE,
  ];
  // @todo the NID field needs different behavior on revision/non-revision
  //   tables. It would be neat if this could be encoded in the base field
  //   definition.
  $data['node_field_revision']['vid'] = [
    'argument' => [
      'id' => 'node_vid',
      'numeric' => TRUE,
    ],
  ] + $data['node_field_revision']['vid'];
  $data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
  $data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
  $data['node_field_revision']['status']['filter']['label'] = $this->t('Published');
  $data['node_field_revision']['status']['filter']['type'] = 'yes-no';
  $data['node_field_revision']['status']['filter']['use_equal'] = TRUE;
  $data['node_field_revision']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
  $data['node_field_revision']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
  $data['node_field_revision']['langcode']['help'] = $this->t('The language of the content or translation.');
  $data['node_field_revision']['link_to_revision'] = [
    'field' => [
      'title' => $this->t('Link to revision'),
      'help' => $this->t('Provide a simple link to the revision.'),
      'id' => 'node_revision_link',
      'click sortable' => FALSE,
    ],
  ];
  $data['node_field_revision']['revert_revision'] = [
    'field' => [
      'title' => $this->t('Link to revert revision'),
      'help' => $this->t('Provide a simple link to revert to the revision.'),
      'id' => 'node_revision_link_revert',
      'click sortable' => FALSE,
    ],
  ];
  $data['node_field_revision']['delete_revision'] = [
    'field' => [
      'title' => $this->t('Link to delete revision'),
      'help' => $this->t('Provide a simple link to delete the content revision.'),
      'id' => 'node_revision_link_delete',
      'click sortable' => FALSE,
    ],
  ];
  // Define the base group of this table. Fields that don't have a group
  // defined will go into this field by default.
  $data['node_access']['table']['group'] = $this->t('Content access');
  // For other base tables, explain how we join.
  $data['node_access']['table']['join'] = [
    'node_field_data' => [
      'left_field' => 'nid',
      'field' => 'nid',
    ],
  ];
  $data['node_access']['nid'] = [
    'title' => $this->t('Access'),
    'help' => $this->t('Filter by access.'),
    'filter' => [
      'id' => 'node_access',
      'help' => $this->t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
    ],
  ];
  return $data;
}

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