diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index d115163..80bd314 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -118,7 +118,7 @@ public function viewElements(FieldItemListInterface $items) { // entity's url. Since we don't know what the markup of the entity will // be, we shouldn't rely on the markup for structured data such as RDFa. if (!empty($item->_attributes)) { - $item->_attributes += array('resource' => $entity->url()); + $item->_attributes += array('resource' => $item->entity->url()); } } else { diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/EntityReferenceRdfaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/EntityReferenceRdfaTest.php index 24aac79..58c6e86 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/EntityReferenceRdfaTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/EntityReferenceRdfaTest.php @@ -21,6 +21,20 @@ class EntityReferenceRdfaTest extends FieldRdfaTestBase { protected $fieldType = 'entity_reference'; /** + * The entity type used in this test. + * + * @var string + */ + protected $entityType = 'entity_test'; + + /** + * The bundle used in this test. + * + * @var string + */ + protected $bundle = 'entity_test'; + + /** * The term for testing. * * @var \Drupal\taxonomy\Entity\Term @@ -45,34 +59,7 @@ public function setUp() { $this->installSchema('entity_test', array('entity_test_rev', 'entity_test_rev_revision')); - $field = entity_create('field_config', array( - 'name' => $this->fieldName, - 'entity_type' => 'entity_test', - 'type' => $this->fieldType - )); - $field->save(); - entity_create('field_instance_config', array( - 'entity_type' => 'entity_test', - 'field_name' => $this->fieldName, - 'bundle' => 'entity_test', - 'settings' => array( - 'handler' => 'default', - 'handler_settings' => array( - 'target_bundles' => array('entity_test' => 'entity_test'), - ), - ), - ))->save(); - - $this->entity = entity_create('entity_test', array( - 'name' => $this->randomName(), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - )); - - $this->target_entity = entity_create('entity_test', array( - 'name' => $this->randomName(), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - )); - $this->target_entity->save(); + entity_reference_create_instance($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType); // Add the mapping. $mapping = rdf_get_mapping('entity_test', 'entity_test'); @@ -80,23 +67,26 @@ public function setUp() { 'properties' => array('schema:knows'), ))->save(); - // Set up test values. - $this->entity->{$this->fieldName}->target_id = $this->target_entity->id(); - $this->entity->{$this->fieldName}->target_type = 'entity_test'; + // Create the entity to be referenced. + $this->target_entity = entity_create($this->entityType, array('name' => $this->randomName())); + $this->target_entity->save(); + // Create the entity that will have the entity reference field. + $this->entity = entity_create($this->entityType, array('name' => $this->randomName())); $this->entity->save(); - $this->uri = $this->getAbsoluteUri($this->entity); + $this->entity->{$this->fieldName}->entity = $this->target_entity; + $this->entity->{$this->fieldName}->access = TRUE; } /** * Tests all the entity reference formatters. */ public function testAllFormatters() { - $entity_uri = $this->getAbsoluteUri($this->target_entity); + $entity_uri = $this->uri . $this->getRelativeUri($this->target_entity); // Tests the label formatter. $this->assertFormatterRdfa(array('type' => 'entity_reference_label'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri')); // Tests the entity formatter. - $this->assertFormatterRdfa(array('type'=>'entity_reference_entity_view'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri')); + $this->assertFormatterRdfa(array('type' => 'entity_reference_entity_view'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri')); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php index 14bcfa1..f34a05b 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php @@ -115,5 +115,8 @@ protected function createTestField() { protected function getAbsoluteUri($entity) { return $entity->url('canonical', array('absolute' => TRUE)); } + protected function getRelativeUri($entity) { + return $entity->url('canonical', array('absolute' => FALSE)); + } }