diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php index ef9a931..095cdf9 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php @@ -113,6 +113,9 @@ public function testAvailableFormatters() { // Create entity reference field with taxonomy term as a target. $taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', 'tags'); + // Create entity reference field with user as a target. + $user_field_name = $this->createEntityReferenceField('user'); + // Create entity reference field with node as a target. $node_field_name = $this->createEntityReferenceField('node', $this->type); @@ -125,7 +128,6 @@ public function testAvailableFormatters() { // Check for Taxonomy Term select box values. // Test if Taxonomy Term Entity Reference Field has the correct formatters. $this->assertFieldSelectOptions('fields[field_' . $taxonomy_term_field_name . '][type]', array( - 'author', 'entity_reference_label', 'entity_reference_entity_id', 'entity_reference_rss_category', @@ -133,10 +135,20 @@ public function testAvailableFormatters() { 'hidden', )); + // Test if User Reference Field has the correct formatters. + // Author should be available for this field. + // RSS Category should not be available for this field. + $this->assertFieldSelectOptions('fields[field_' . $user_field_name . '][type]', array( + 'author', + 'entity_reference_entity_id', + 'entity_reference_entity_view', + 'entity_reference_label', + 'hidden', + )); + // Test if Node Entity Reference Field has the correct formatters. // RSS Category should not be available for this field. $this->assertFieldSelectOptions('fields[field_' . $node_field_name . '][type]', array( - 'author', 'entity_reference_label', 'entity_reference_entity_id', 'entity_reference_entity_view', @@ -147,7 +159,6 @@ public function testAvailableFormatters() { // RSS Category & Entity View should not be available for this field. // This could be any field without a ViewBuilder. $this->assertFieldSelectOptions('fields[field_' . $date_format_field_name . '][type]', array( - 'author', 'entity_reference_label', 'entity_reference_entity_id', 'hidden', diff --git a/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php b/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php index 38c7f55..43054a6 100644 --- a/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php +++ b/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php @@ -7,6 +7,7 @@ namespace Drupal\user\Plugin\Field\FieldFormatter; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; @@ -47,4 +48,7 @@ public function viewElements(FieldItemListInterface $items) { return $elements; } + public static function isApplicable(FieldDefinitionInterface $field_definition) { + return $field_definition->getFieldStorageDefinition()->getSetting('target_type') == 'user'; + } }