diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php index e78702933d7a8df5857d5e5455652647d440ccb0..84d1ec582b7dd929b158d174517209afeaef0682 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php @@ -18,7 +18,8 @@ * id = "uuid", * label = @Translation("UUID"), * description = @Translation("An entity field containing a UUID."), - * no_ui = TRUE + * no_ui = TRUE, + * default_formatter = "string" * ) */ class UuidItem extends StringItem { diff --git a/core/modules/comment/src/Tests/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/src/Tests/Views/CommentViewsFieldAccessTest.php index 34a588272e194f3a74ecf8ec8c66112a1bb8d02c..7cf72557aad540eaa7af2b9a5dd76424b8ed3d2e 100644 --- a/core/modules/comment/src/Tests/Views/CommentViewsFieldAccessTest.php +++ b/core/modules/comment/src/Tests/Views/CommentViewsFieldAccessTest.php @@ -66,7 +66,7 @@ public function testCommentFields() { // $this->assertFieldAccess('comment', 'cid', $comment->id()); // $this->assertFieldAccess('comment', 'cid', $comment_anonymous->id()); - // $this->assertFieldAccess('comment', 'uuid', $comment->uuid()); + $this->assertFieldAccess('comment', 'uuid', $comment->uuid()); // $this->assertFieldAccess('comment', 'subject', 'My comment title'); // $this->assertFieldAccess('comment', 'subject', 'Anonymous comment title'); $this->assertFieldAccess('comment', 'name', 'anonymous'); diff --git a/core/modules/field/src/Tests/String/UuidFormatterTest.php b/core/modules/field/src/Tests/String/UuidFormatterTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2eaf7e9424664bf026092a32a7ddd1a0aaca7087 --- /dev/null +++ b/core/modules/field/src/Tests/String/UuidFormatterTest.php @@ -0,0 +1,58 @@ +<?php + +/** + * @file + * Contains \Drupal\field\Tests\String\UuidFormatterTest. + */ + +namespace Drupal\field\Tests\String; + +use Drupal\simpletest\KernelTestBase; +use Drupal\entity_test\Entity\EntityTest; + +/** + * Tests the output of a UUID field. + * + * @group field + */ +class UuidFormatterTest extends KernelTestBase { + + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = ['field', 'entity_test', 'system', 'user']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->installConfig(['system', 'field']); + $this->installSchema('system', 'router'); + \Drupal::service('router.builder')->rebuild(); + $this->installEntitySchema('entity_test'); + } + + /** + * Tests string formatter output. + */ + public function testUuidStringFormatter() { + $entity = EntityTest::create([]); + $entity->save(); + + $uuid_field = $entity->get('uuid'); + + $render_array = $uuid_field->view([]); + $this->assertIdentical($render_array[0]['#markup'], $entity->uuid(), 'The rendered UUID matches the entity UUID.'); + + $render_array = $uuid_field->view(['settings' => ['link_to_entity' => TRUE]]); + $this->assertIdentical($render_array[0]['#type'], 'link'); + $this->assertIdentical($render_array[0]['#title'], $entity->uuid()); + $this->assertIdentical($render_array[0]['#url']->toString(), $entity->url()); + } + +} diff --git a/core/modules/file/src/Tests/Views/FileViewsFieldAccessTest.php b/core/modules/file/src/Tests/Views/FileViewsFieldAccessTest.php index 74baac34e7f58d4028cb5cfbd97b87d360c75bb5..94adad341e6cd8f3bea77091710ccd5118b2963d 100644 --- a/core/modules/file/src/Tests/Views/FileViewsFieldAccessTest.php +++ b/core/modules/file/src/Tests/Views/FileViewsFieldAccessTest.php @@ -60,7 +60,7 @@ public function testFileFields() { // @todo Expand the test coverage in https://www.drupal.org/node/2464635 $this->assertFieldAccess('file', 'fid', $file->id()); - // $this->assertFieldAccess('file', 'uuid', $file->uuid()); + $this->assertFieldAccess('file', 'uuid', $file->uuid()); $this->assertFieldAccess('file', 'langcode', $file->language()->getName()); $this->assertFieldAccess('file', 'uid', 'test user'); $this->assertFieldAccess('file', 'filename', $file->getFilename()); diff --git a/core/modules/node/src/Tests/Views/NodeViewsFieldAccessTest.php b/core/modules/node/src/Tests/Views/NodeViewsFieldAccessTest.php index 0ed8edf0bcf4b7770a989da5cc913a2537217eb0..93772f9cae70205113d1401e2532a5e3adcc3ae6 100644 --- a/core/modules/node/src/Tests/Views/NodeViewsFieldAccessTest.php +++ b/core/modules/node/src/Tests/Views/NodeViewsFieldAccessTest.php @@ -59,7 +59,7 @@ public function testNodeFields() { // @todo Expand the test coverage in https://www.drupal.org/node/2464635 $this->assertFieldAccess('node', 'nid', $node->id()); - // $this->assertFieldAccess('node', 'uuid', $node->uuid()); + $this->assertFieldAccess('node', 'uuid', $node->uuid()); $this->assertFieldAccess('node', 'vid', $node->id()); $this->assertFieldAccess('node', 'type', $node->type->entity->label()); $this->assertFieldAccess('node', 'langcode', $node->language()->getName()); diff --git a/core/modules/user/src/Tests/Views/UserViewsFieldAccessTest.php b/core/modules/user/src/Tests/Views/UserViewsFieldAccessTest.php index f9782295126298e28c54b7b93fcf967820e97d77..09ee466175e34b225b27bedcc5822009b7fbf7d8 100644 --- a/core/modules/user/src/Tests/Views/UserViewsFieldAccessTest.php +++ b/core/modules/user/src/Tests/Views/UserViewsFieldAccessTest.php @@ -57,7 +57,7 @@ public function testUserFields() { // @todo Expand the test coverage in https://www.drupal.org/node/2464635 // $this->assertFieldAccess('user', 'uid', $user->id()); - // $this->assertFieldAccess('user', 'uuid', $user->uuid()); + $this->assertFieldAccess('user', 'uuid', $user->uuid()); $this->assertFieldAccess('user', 'langcode', $user->language()->getName()); $this->assertFieldAccess('user', 'preferred_langcode', 'Spanish'); $this->assertFieldAccess('user', 'preferred_admin_langcode', 'French'); diff --git a/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php index 44ea7087bdd9670c9aa8af0837197d88f72742a3..5554a8adc9a94ca0f5d71f36c9db6c72fa7a6030 100644 --- a/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php +++ b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php @@ -90,7 +90,10 @@ protected function assertFieldAccess($entity_type_id, $field_name, $field_conten $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); $view_id = $this->randomMachineName(); - $base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable(); + $data_table = $entity_type->getDataTable(); + // Use the data table as long as the field is not 'uuid'. This is the only + // column that can only be obtained from the base table. + $base_table = ($data_table && ($field_name !== 'uuid')) ? $data_table : $entity_type->getBaseTable(); $entity = View::create([ 'id' => $view_id, 'base_table' => $base_table,