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
...@@ -306,6 +306,13 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co ...@@ -306,6 +306,13 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
$views_field['sort']['id'] = 'standard'; $views_field['sort']['id'] = 'standard';
break; 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':
case 'text_with_summary': case 'text_with_summary':
// Treat these three long text fields the same. // Treat these three long text fields the same.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
use Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem; use Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem;
use Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem; use Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem; 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\Core\Field\Plugin\Field\FieldType\UuidItem;
use Drupal\text\Plugin\Field\FieldType\TextLongItem; use Drupal\text\Plugin\Field\FieldType\TextLongItem;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
...@@ -138,6 +139,13 @@ protected function setupBaseFields(array $base_fields) { ...@@ -138,6 +139,13 @@ protected function setupBaseFields(array $base_fields) {
)) ))
->setDisplayConfigurable('form', TRUE); ->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) { foreach ($base_fields as $name => $base_field) {
$base_field->setName($name); $base_field->setName($name);
} }
...@@ -246,6 +254,10 @@ protected function setupFieldStorageDefinition() { ...@@ -246,6 +254,10 @@ protected function setupFieldStorageDefinition() {
$description_field_storage_definition->expects($this->any()) $description_field_storage_definition->expects($this->any())
->method('getSchema') ->method('getSchema')
->willReturn(TextLongItem::schema($description_field_storage_definition)); ->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. // Setup the user_id entity reference field.
$this->entityManager->expects($this->any()) $this->entityManager->expects($this->any())
...@@ -277,6 +289,7 @@ protected function setupFieldStorageDefinition() { ...@@ -277,6 +289,7 @@ protected function setupFieldStorageDefinition() {
'langcode' => $langcode_field_storage_definition, 'langcode' => $langcode_field_storage_definition,
'name' => $name_field_storage_definition, 'name' => $name_field_storage_definition,
'description' => $description_field_storage_definition, 'description' => $description_field_storage_definition,
'homepage' => $homepage_field_storage_definition,
'user_id' => $user_id_field_storage_definition, 'user_id' => $user_id_field_storage_definition,
'revision_id' => $revision_id_field_storage_definition, 'revision_id' => $revision_id_field_storage_definition,
]); ]);
...@@ -307,12 +320,13 @@ public function testBaseTableFields() { ...@@ -307,12 +320,13 @@ public function testBaseTableFields() {
['langcode', ['value' => 'langcode']], ['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']], ['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']], ['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']], ['user_id', ['target_id' => 'user_id']],
]); ]);
$table_mapping->expects($this->any()) $table_mapping->expects($this->any())
->method('getFieldNames') ->method('getFieldNames')
->willReturnMap([ ->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()) $this->entityStorage->expects($this->once())
...@@ -334,6 +348,8 @@ public function testBaseTableFields() { ...@@ -334,6 +348,8 @@ public function testBaseTableFields() {
$this->assertLongTextField($data['entity_test'], 'description'); $this->assertLongTextField($data['entity_test'], 'description');
$this->assertUriField($data['entity_test']['homepage']);
$this->assertEntityReferenceField($data['entity_test']['user_id']); $this->assertEntityReferenceField($data['entity_test']['user_id']);
$relationship = $data['entity_test']['user_id']['relationship']; $relationship = $data['entity_test']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']); $this->assertEquals('users', $relationship['base']);
...@@ -386,13 +402,14 @@ public function testDataTableFields() { ...@@ -386,13 +402,14 @@ public function testDataTableFields() {
['langcode', ['value' => 'langcode']], ['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']], ['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']], ['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']], ['user_id', ['target_id' => 'user_id']],
]); ]);
$table_mapping->expects($this->any()) $table_mapping->expects($this->any())
->method('getFieldNames') ->method('getFieldNames')
->willReturnMap([ ->willReturnMap([
['entity_test_mul', ['id', 'uuid', 'type', 'langcode']], ['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()) $this->entityStorage->expects($this->once())
...@@ -417,6 +434,7 @@ public function testDataTableFields() { ...@@ -417,6 +434,7 @@ public function testDataTableFields() {
$this->assertFalse(isset($data['entity_test_mul']['description__value'])); $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']['description__format']));
$this->assertFalse(isset($data['entity_test_mul']['user_id'])); $this->assertFalse(isset($data['entity_test_mul']['user_id']));
$this->assertFalse(isset($data['entity_test_mul']['homepage']));
// Check the data fields. // Check the data fields.
$this->assertNumericField($data['entity_test_mul_property_data']['id']); $this->assertNumericField($data['entity_test_mul_property_data']['id']);
...@@ -428,6 +446,8 @@ public function testDataTableFields() { ...@@ -428,6 +446,8 @@ public function testDataTableFields() {
$this->assertLongTextField($data['entity_test_mul_property_data'], 'description'); $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']); $this->assertEntityReferenceField($data['entity_test_mul_property_data']['user_id']);
$relationship = $data['entity_test_mul_property_data']['user_id']['relationship']; $relationship = $data['entity_test_mul_property_data']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']); $this->assertEquals('users', $relationship['base']);
...@@ -466,6 +486,7 @@ public function testRevisionTableFields() { ...@@ -466,6 +486,7 @@ public function testRevisionTableFields() {
['langcode', ['value' => 'langcode']], ['langcode', ['value' => 'langcode']],
['name', ['value' => 'name']], ['name', ['value' => 'name']],
['description', ['value' => 'description__value', 'format' => 'description__format']], ['description', ['value' => 'description__value', 'format' => 'description__format']],
['homepage', ['value' => 'homepage']],
['user_id', ['target_id' => 'user_id']], ['user_id', ['target_id' => 'user_id']],
['revision_id', ['value' => 'id']], ['revision_id', ['value' => 'id']],
]); ]);
...@@ -474,8 +495,8 @@ public function testRevisionTableFields() { ...@@ -474,8 +495,8 @@ public function testRevisionTableFields() {
->willReturnMap([ ->willReturnMap([
['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']], ['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']],
['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']], ['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_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']],
['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'user_id']], ['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']],
]); ]);
$this->entityStorage->expects($this->once()) $this->entityStorage->expects($this->once())
...@@ -497,6 +518,7 @@ public function testRevisionTableFields() { ...@@ -497,6 +518,7 @@ public function testRevisionTableFields() {
$this->assertFalse(isset($data['entity_test_mul']['description'])); $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__value']));
$this->assertFalse(isset($data['entity_test_mul']['description__format'])); $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']['langcode']));
$this->assertFalse(isset($data['entity_test_mulrev']['user_id'])); $this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
...@@ -512,6 +534,7 @@ public function testRevisionTableFields() { ...@@ -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']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value'])); $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']['description__format']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
$this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id'])); $this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
// Check the data fields. // Check the data fields.
...@@ -520,6 +543,7 @@ public function testRevisionTableFields() { ...@@ -520,6 +543,7 @@ public function testRevisionTableFields() {
$this->assertStringField($data['entity_test_mulrev_property_data']['name']); $this->assertStringField($data['entity_test_mulrev_property_data']['name']);
$this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description'); $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']); $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
$relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship']; $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
...@@ -536,6 +560,8 @@ public function testRevisionTableFields() { ...@@ -536,6 +560,8 @@ public function testRevisionTableFields() {
$this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description'); $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']); $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
$relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship']; $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
$this->assertEquals('users', $relationship['base']); $this->assertEquals('users', $relationship['base']);
...@@ -555,6 +581,19 @@ protected function assertStringField($data) { ...@@ -555,6 +581,19 @@ protected function assertStringField($data) {
$this->assertEquals('standard', $data['sort']['id']); $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. * 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