Steps for reproducing


Create an "Album" content type and a "Photo" content type. The Photo content type has an image field (field_photo) and an entity reference field (field_album) that references nodes of type Album. The Album content type has an entity reference field (field_cover_photo) with its reference method set to filter using the view shown below.


To make this bug more readily visible, change the form display widgets for the field_cover_photo and field_album fields in the Album and Photo content types from "Autocomplete" to "Check boxes/radio buttons".


Create two Album nodes, an "Album A" and an "Album B". Create four Photo nodes, assign two each to the "Album A" and "Album B" nodes.


Edit the "Album A" node. Notice that the cover photo field shows two radio buttons, one for the N/A item the other for the "Album B" node. This is incorrect, it should be showing three radio buttons, the N/A item and the two Photo nodes that were assigned to "Album A" (see attached screenshot).


uuid: b4bd9223-076f-4232-9800-0d37c80d3e56
langcode: en
status: true
dependencies:
  config:
    - field.storage.node.field_photo
    - node.type.album
  module:
    - entity_reference
    - image
    - node
    - user
id: album_photos
label: 'Album Photos'
module: views
description: ''
tag: ''
base_table: node
base_field: nid
core: 8.x
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: none
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: false
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: full
        options:
          items_per_page: 10
          offset: 0
          id: 0
          total_pages: null
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          tags:
            previous: '‹ previous'
            next: 'next ›'
            first: '« first'
            last: 'last »'
          quantity: 9
      style:
        type: default
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
          uses_fields: false
      row:
        type: fields
        options:
          inline: {  }
          separator: ''
          hide_empty: false
          default_field_elements: true
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          relationship: reverse__node__field_album
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: ''
            word_boundary: false
            ellipsis: false
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          link_to_node: false
          entity_type: node
          entity_field: title
          plugin_id: node
        field_photo:
          id: field_photo
          table: node__field_photo
          field: field_photo
          relationship: reverse__node__field_album
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: ''
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: target_id
          type: image
          settings:
            image_style: thumbnail
            image_link: ''
          group_column: ''
          group_columns: {  }
          group_rows: true
          delta_limit: all
          delta_offset: '0'
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          plugin_id: field
      filters:
        type:
          id: type
          table: node
          field: type
          value:
            album: album
          entity_type: node
          entity_field: type
          plugin_id: bundle
      sorts: {  }
      header: {  }
      footer: {  }
      empty: {  }
      relationships:
        reverse__node__field_album:
          id: reverse__node__field_album
          table: node
          field: reverse__node__field_album
          relationship: none
          group_type: group
          admin_label: field_album
          required: true
          entity_type: node
          plugin_id: entity_reverse
      arguments:
        nid:
          id: nid
          table: node_field_data
          field: nid
          relationship: none
          group_type: group
          admin_label: ''
          default_action: default
          exception:
            value: all
            title_enable: false
            title: All
          title_enable: false
          title: ''
          default_argument_type: node
          default_argument_options: {  }
          default_argument_skip_url: false
          summary_options:
            base_path: ''
            count: true
            items_per_page: 25
            override: false
          summary:
            sort_order: asc
            number_of_records: 0
            format: default_summary
          specify_validation: true
          validate:
            type: 'entity:node'
            fail: 'not found'
          validate_options:
            bundles:
              album: album
            operation: view
            multiple: '0'
            access: 0
          break_phrase: false
          not: false
          entity_type: node
          entity_field: nid
          plugin_id: numeric
      display_extenders: {  }
      field_langcode: '***LANGUAGE_language_content***'
      field_langcode_add_to_query: null
  entity_reference_1:
    display_plugin: entity_reference
    id: entity_reference_1
    display_title: 'Entity Reference'
    position: 1
    display_options:
      display_extenders: {  }
      field_langcode: '***LANGUAGE_language_content***'
      field_langcode_add_to_query: null
      style:
        type: entity_reference
        options:
          search_fields:
            title: title
      pager:
        type: none
        options:
          offset: 0


CommentFileSizeAuthor
Edit-Album-A-error.png81.7 KBkbjohnson

Comments

kbjohnson’s picture

Assigned: Unassigned » kbjohnson
diff --git a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
index 139f2f6..a2c3f75 100644
--- a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
+++ b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
@@ -169,8 +169,21 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA
 
     $return = array();
     if ($result) {
-      foreach($this->view->result as $row) {
-        $entity = $row->_entity;
+    $relationship_id = 'none';
+    foreach($this->view->field as $field) {
+      if (isset($field->relationship)) {
+        $relationship_id = $field->options['relationship'];
+        break;
+      }
+    }
+    
+      foreach($this->view->result as $row) {
+      if ($relationship_id == 'none') {
+          $entity = $row->_entity;
+        }
+        else {
+          $entity = $row->_relationship_entities[$relationship_id];
+        }
         $return[$entity->bundle()][$entity->id()] = $entity->label();
       }
     }
kbjohnson’s picture

Assigned: kbjohnson » Unassigned
highermath’s picture

Priority: Major » Minor
Status: Needs review » Postponed (maintainer needs more info)

Current head will not import this view code through configuration import. Steps to recreate through Views UI might be useful.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jonathanshaw’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)