closedquestion-8.x-3.x-dev/src/ClosedQuestionViewsData.php
src/ClosedQuestionViewsData.php
<?php
namespace Drupal\closedquestion;
use Drupal\views\EntityViewsData;
/**
* Provides the views data for the closed question entity type.
*/
class ClosedQuestionViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
$data['closedquestion_field_data']['table']['base']['weight'] = -10;
$data['closedquestion_field_data']['table']['base']['access query tag'] = 'closedquestion_access';
$data['closedquestion_field_data']['table']['wizard_id'] = 'closedquestion';
$data['closedquestion_field_data']['id']['argument'] = [
'id' => 'closedquestion_id',
'name field' => 'title',
'numeric' => TRUE,
'validate type' => 'id',
];
$data['closedquestion_field_data']['title']['field']['default_formatter_settings'] = ['link_to_entity' => TRUE];
$data['closedquestion_field_data']['title']['field']['link_to_closedquestion default'] = TRUE;
$data['closedquestion_field_data']['langcode']['help'] = $this->t('The language of the closed question or translation.');
$data['closedquestion_field_data']['status']['filter']['label'] = $this->t('Published status');
$data['closedquestion_field_data']['status']['filter']['type'] = 'yes-no';
// Use status = 1 instead of status <> 0 in WHERE statement.
$data['closedquestion_field_data']['status']['filter']['use_equal'] = TRUE;
$data['closedquestion_field_data']['status_extra'] = [
'title' => $this->t('Published status or admin user'),
'help' => $this->t('Filters out unpublished closed questions if the current user cannot view it.'),
'filter' => [
'field' => 'status',
'id' => 'closedquestion_status',
'label' => $this->t('Published status or admin user'),
],
];
$data['closedquestion']['closedquestion_bulk_form'] = [
'title' => $this->t('Closed question operations bulk form'),
'help' => $this->t('Add a form element that lets you run operations on multiple closed questions.'),
'field' => [
'id' => 'closedquestion_bulk_form',
],
];
// Bogus fields for aliasing purposes.
// @todo Add similar support to any date field
// @see https://www.drupal.org/node/2337507
$data['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_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['closedquestion_field_data']['uid']['help'] = $this->t('The user authoring the closed question. If you need more fields than the uid add the closed question: author relationship');
$data['closedquestion_field_data']['uid']['filter']['id'] = 'user_name';
$data['closedquestion_field_data']['uid']['relationship']['title'] = $this->t('Closed Question author');
$data['closedquestion_field_data']['uid']['relationship']['help'] = $this->t('Relate closed question to the user who created it.');
$data['closedquestion_field_data']['uid']['relationship']['label'] = $this->t('author');
return $data;
}
}
