Commit 412e7334 authored by alexpott's avatar alexpott

Issue #2320277 by jhodgdon: Fixed Views comment language field/filter is for...

Issue #2320277 by jhodgdon: Fixed Views comment language field/filter is for original language code, no translation language field/filter.
parent b1fa3ac3
......@@ -7,186 +7,44 @@
namespace Drupal\comment;
use Drupal\views\EntityViewsDataInterface;
use Drupal\views\EntityViewsData;
/**
* Provides views data for the comment entity type.
*/
class CommentViewsData implements EntityViewsDataInterface {
class CommentViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['comment']['table']['group'] = t('Comment');
$data = parent::getViewsData();
$data['comment']['table']['base']['help'] = t('Comments are responses to content.');
$data['comment']['table']['base']['access query tag'] = 'comment_access';
$data['comment']['table']['base'] = array(
'field' => 'cid',
'title' => t('Comment'),
'help' => t("Comments are responses to node content."),
'access query tag' => 'comment_access',
);
$data['comment']['table']['entity type'] = 'comment';
$data['comment']['table']['wizard_id'] = 'comment';
$data['comment_field_data']['table']['group'] = t('Comment');
$data['comment_field_data']['table']['entity type'] = 'comment';
$data['comment_field_data']['table']['join']['comment'] = array(
'type' => 'INNER',
'left_field' => 'cid',
'field' => 'cid',
);
$data['comment_field_data']['subject']['title'] = t('Title');
$data['comment_field_data']['subject']['help'] = t('The title of the comment.');
$data['comment_field_data']['subject']['field']['id'] = 'comment';
$data['comment_field_data']['subject'] = array(
'title' => t('Title'),
'help' => t('The title of the comment.'),
'field' => array(
'id' => 'comment',
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'string',
),
);
$data['comment']['cid']['field']['id'] = 'comment';
$data['comment']['cid'] = array(
'title' => t('ID'),
'help' => t('The comment ID of the field'),
'field' => array(
'id' => 'comment',
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'numeric',
),
);
$data['comment_field_data']['name']['title'] = t('Author');
$data['comment_field_data']['name']['help'] = t("The name of the comment's author. Can be rendered as a link to the author's homepage.");
$data['comment_field_data']['name']['field']['id'] = 'comment_username';
$data['comment_field_data']['name'] = array(
'title' => t('Author'),
'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
'field' => array(
'id' => 'comment_username',
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'string',
),
);
$data['comment_field_data']['homepage'] = array(
'title' => t("Author's website"),
'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
'field' => array(
'id' => 'url',
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'string',
),
);
$data['comment_field_data']['homepage']['title'] = t("Author's website");
$data['comment_field_data']['homepage']['help'] = t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user.");
$data['comment_field_data']['hostname'] = array(
'title' => t('Hostname'),
'help' => t('Hostname of user that posted the comment.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'string',
),
);
$data['comment_field_data']['mail']['help'] = t('Email of user that posted the comment. Will be empty if the author is a registered user.');
$data['comment_field_data']['mail'] = array(
'title' => t('Email'),
'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'string',
),
);
$data['comment_field_data']['created']['title'] = t('Post date');
$data['comment_field_data']['created']['help'] = t('Date and time of when the comment was created.');
$data['comment_field_data']['created'] = array(
'title' => t('Post date'),
'help' => t('Date and time of when the comment was created.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date',
),
'filter' => array(
'id' => 'date',
),
);
if (\Drupal::moduleHandler()->moduleExists('language')) {
$data['comment']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the comment is in.'),
'field' => array(
'id' => 'language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
$data['comment_field_data']['changed'] = array(
'title' => t('Updated date'),
'help' => t('Date and time of when the comment was last updated.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date',
),
'filter' => array(
'id' => 'date',
),
);
$data['comment_field_data']['changed']['title'] = t('Updated date');
$data['comment_field_data']['changed']['help'] = t('Date and time of when the comment was last updated.');
$data['comment_field_data']['changed_fulldata'] = array(
'title' => t('Created date'),
......@@ -242,24 +100,13 @@ public function getViewsData() {
),
);
$data['comment_field_data']['status'] = array(
'title' => t('Approved status'),
'help' => t('Whether the comment is approved (or still in the moderation queue).'),
'field' => array(
'id' => 'boolean',
'output formats' => array(
'approved-not-approved' => array(t('Approved'), t('Not Approved')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Approved comment status'),
'type' => 'yes-no',
),
'sort' => array(
'id' => 'standard',
),
$data['comment_field_data']['status']['title'] = t('Approved status');
$data['comment_field_data']['status']['help'] = t('Whether the comment is approved (or still in the moderation queue).');
$data['comment_field_data']['status']['field']['output formats'] = array(
'approved-not-approved' => array(t('Approved'), t('Not Approved')),
);
$data['comment_field_data']['status']['filter']['label'] = t('Approved comment status');
$data['comment_field_data']['status']['filter']['type'] = 'yes-no';
$data['comment']['view_comment'] = array(
'field' => array(
......@@ -301,52 +148,18 @@ public function getViewsData() {
),
);
$data['comment_field_data']['thread'] = array(
'field' => array(
'title' => t('Depth'),
'help' => t('Display the depth of the comment if it is threaded.'),
'id' => 'comment_depth',
),
'sort' => array(
'title' => t('Thread'),
'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
'id' => 'comment_thread',
),
$data['comment_field_data']['thread']['field'] = array(
'title' => t('Depth'),
'help' => t('Display the depth of the comment if it is threaded.'),
'id' => 'comment_depth',
);
$data['comment_field_data']['entity_id'] = array(
'title' => t('Entity ID'),
'help' => t('The Entity ID to which the comment is a reply to.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'numeric',
),
'argument' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
);
$data['comment_field_data']['entity_type'] = array(
'title' => t('Entity type'),
'help' => t('The Entity type to which the comment is a reply to.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
$data['comment_field_data']['thread']['sort'] = array(
'title' => t('Thread'),
'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
'id' => 'comment_thread',
);
unset($data['comment_field_data']['thread']['filter']);
unset($data['comment_field_data']['thread']['argument']);
$data['comment_field_data']['field_name'] = array(
'title' => t('Comment field name'),
......@@ -365,23 +178,6 @@ public function getViewsData() {
),
);
$data['comment']['comment_type'] = array(
'title' => t('Comment type'),
'help' => t('The comment type for this comment.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
$entities_types = \Drupal::entityManager()->getDefinitions();
// Provide a relationship for each entity type except comment.
......@@ -411,43 +207,17 @@ public function getViewsData() {
}
}
$data['comment_field_data']['uid'] = array(
'title' => t('Author uid'),
'help' => t('If you need more fields than the uid add the comment: author relationship'),
'relationship' => array(
'title' => t('Author'),
'help' => t("The User ID of the comment's author."),
'base' => 'users',
'base field' => 'uid',
'id' => 'standard',
'label' => t('author'),
),
'filter' => array(
'id' => 'numeric',
),
'argument' => array(
'id' => 'numeric',
),
'field' => array(
'id' => 'user',
),
);
$data['comment_field_data']['pid'] = array(
'title' => t('Parent CID'),
'help' => t('The Comment ID of the parent comment.'),
'field' => array(
'id' => 'standard',
),
'relationship' => array(
'title' => t('Parent comment'),
'help' => t('The parent comment.'),
'base' => 'comment',
'base field' => 'cid',
'id' => 'standard',
'label' => t('Parent comment'),
),
);
$data['comment_field_data']['uid']['title'] = t('Author uid');
$data['comment_field_data']['uid']['help'] = t('If you need more fields than the uid add the comment: author relationship');
$data['comment_field_data']['uid']['relationship']['title'] = t('Author');
$data['comment_field_data']['uid']['relationship']['help'] = t("The User ID of the comment's author.");
$data['comment_field_data']['uid']['relationship']['label'] = t('author');
$data['comment_field_data']['uid']['field']['id'] = 'user';
$data['comment_field_data']['pid']['title'] = t('Parent CID');
$data['comment_field_data']['pid']['relationship']['title'] = t('Parent comment');
$data['comment_field_data']['pid']['relationship']['help'] = t('The parent comment');
$data['comment_field_data']['pid']['relationship']['label'] = t('parent');
if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
$data['comment']['translation_link'] = array(
......
......@@ -306,6 +306,13 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
$views_field['sort']['id'] = 'standard';
break;
case 'uri':
$views_field['field']['id'] = 'url';
$views_field['argument']['id'] = 'string';
$views_field['filter']['id'] = 'string';
$views_field['sort']['id'] = 'standard';
break;
case 'text':
case 'text_with_summary':
// Treat these three long text fields the same.
......
......@@ -16,6 +16,7 @@
use Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem;
use Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
use Drupal\Core\Field\Plugin\Field\FieldType\UriItem;
use Drupal\Core\Field\Plugin\Field\FieldType\UuidItem;
use Drupal\text\Plugin\Field\FieldType\TextLongItem;
use Drupal\entity_test\Entity\EntityTest;
......@@ -138,6 +139,13 @@ protected function setupBaseFields(array $base_fields) {
))
->setDisplayConfigurable('form', TRUE);
// Add a URL field; this example is from the Comment entity.
$base_fields['homepage'] = BaseFieldDefinition::create('uri')
->setLabel(t('Homepage'))
->setDescription(t("The comment author's home page address."))
->setTranslatable(TRUE)
->setSetting('max_length', 255);
foreach ($base_fields as $name => $base_field) {
$base_field->setName($name);
}
......@@ -246,6 +254,10 @@ protected function setupFieldStorageDefinition() {
$description_field_storage_definition->expects($this->any())
->method('getSchema')
->willReturn(TextLongItem::schema($description_field_storage_definition));
$homepage_field_storage_definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$homepage_field_storage_definition->expects($this->any())
->method('getSchema')
->willReturn(UriItem::schema($homepage_field_storage_definition));
// Setup the user_id entity reference field.
$this->entityManager->expects($this->any())
......@@ -277,6 +289,7 @@ protected function setupFieldStorageDefinition() {
'langcode' => $langcode_field_storage_definition,
'name' => $name_field_storage_definition,
'description' => $description_field_storage_definition,
'homepage' => $homepage_field_storage_definition,
'user_id' => $user_id_field_storage_definition,
'revision_id' => $revision_id_field_storage_definition,
]);
......@@ -307,12 +320,13 @@ public function testBaseTableFields() {
['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']],
]);
$table_mapping->expects($this->any())
->method('getFieldNames')
->willReturnMap([
['entity_test', ['id', 'uuid', 'type', 'langcode', 'name', 'description', 'user_id']]
['entity_test', ['id', 'uuid', 'type', 'langcode', 'name', 'description', 'homepage', 'user_id']]
]);
$this->entityStorage->expects($this->once())
......@@ -334,6 +348,8 @@ public function testBaseTableFields() {
$this->assertLongTextField($data['entity_test'], 'description');
$this->assertUriField($data['entity_test']['homepage']);
$this->assertEntityReferenceField($data['entity_test']['user_id']);
$relationship = $data['entity_test']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']);
......@@ -386,13 +402,14 @@ public function testDataTableFields() {
['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']],
]);
$table_mapping->expects($this->any())
->method('getFieldNames')
->willReturnMap([
['entity_test_mul', ['id', 'uuid', 'type', 'langcode']],
['entity_test_mul_property_data', ['id', 'langcode', 'name', 'description', 'user_id']],
['entity_test_mul_property_data', ['id', 'langcode', 'name', 'description', 'homepage', 'user_id']],
]);
$this->entityStorage->expects($this->once())
......@@ -417,6 +434,7 @@ public function testDataTableFields() {
$this->assertFalse(isset($data['entity_test_mul']['description__value']));
$this->assertFalse(isset($data['entity_test_mul']['description__format']));
$this->assertFalse(isset($data['entity_test_mul']['user_id']));
$this->assertFalse(isset($data['entity_test_mul']['homepage']));
// Check the data fields.
$this->assertNumericField($data['entity_test_mul_property_data']['id']);
......@@ -428,6 +446,8 @@ public function testDataTableFields() {
$this->assertLongTextField($data['entity_test_mul_property_data'], 'description');
$this->assertUriField($data['entity_test_mul_property_data']['homepage']);
$this->assertEntityReferenceField($data['entity_test_mul_property_data']['user_id']);
$relationship = $data['entity_test_mul_property_data']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']);
......@@ -466,6 +486,7 @@ public function testRevisionTableFields() {
['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']],
['revision_id', ['value' => 'id']],
]);
......@@ -474,8 +495,8 @@ public function testRevisionTableFields() {
->willReturnMap([
['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']],
['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']],
['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'user_id']],
['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'user_id']],
['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']],
['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']],
]);
$this->entityStorage->expects($this->once())
......@@ -497,6 +518,7 @@ public function testRevisionTableFields() {
$this->assertFalse(isset($data['entity_test_mul']['description']));
$this->assertFalse(isset($data['entity_test_mul']['description__value']));
$this->assertFalse(isset($data['entity_test_mul']['description__format']));
$this->assertFalse(isset($data['entity_test_mul']['homepage']));
$this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
$this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
......@@ -512,6 +534,7 @@ public function testRevisionTableFields() {
$this->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
// Check the data fields.
......@@ -520,6 +543,7 @@ public function testRevisionTableFields() {
$this->assertStringField($data['entity_test_mulrev_property_data']['name']);
$this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
$this->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
$this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
$relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
......@@ -536,6 +560,8 @@ public function testRevisionTableFields() {
$this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
$this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
$this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
$relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']);
......@@ -555,6 +581,19 @@ protected function assertStringField($data) {
$this->assertEquals('standard', $data['sort']['id']);
}
/**
* Tests views data for a URI field.
*
* @param $data
* The views data to check.
*/
protected function assertUriField($data) {
$this->assertEquals('url', $data['field']['id']);
$this->assertEquals('string', $data['filter']['id']);
$this->assertEquals('string', $data['argument']['id']);
$this->assertEquals('standard', $data['sort']['id']);
}
/**
* Tests views data for a long text field.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment