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 623140f..f020d11 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
@@ -101,6 +101,7 @@ public function viewElements(FieldItemListInterface $items) {
           // Hide the element links.
           $elements[$delta][$target_type][$item->target_id]['links']['#access'] = FALSE;
         }
+        $item->_attributes += array('resource' => 'node/' . $item->target_id);
       }
       else {
         // This is an "auto_create" item.
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php
index 7cdac18..cbe257e 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php
@@ -75,6 +75,14 @@ public function viewElements(FieldItemListInterface $items) {
             '#type' => 'link',
             '#title' => $label,
           ) + $uri->toRenderArray();
+
+          if (!empty($item->_attributes)) {
+            $elements[$delta]['#options'] += array('attributes' => array());
+            $elements[$delta]['#options']['attributes'] += $item->_attributes;
+            // Unset field item attributes since they have been included in the
+            // formatter output and should not be rendered in the field template.
+            unset($item->_attributes);
+          }
         }
         else {
           $elements[$delta] = array('#markup' => check_plain($label));
