Problem/Motivation

The split between Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem and Drupal\entity_reference\ConfigurableEntityReferenceItem, one being swapped with the other as implementing the 'entity_reference' field type when entity_reference/module is enabled :
- Makes no sense now that all the "extended features" provided by the module (widgets, formatters, selection plugins) progressively made their way into core. The split is now purley artifical, the Core class provides a full-features field type that just omits the methods allowing it to be used for configurable fields in Field UI, the other one just adds the UI methods.
- Only adds major confusion (two classes for a field type, which one runs depends on enabled modules) and maintainance burden for an already complex field type :-)
- Is broken, since entity_reference.module contains housekeeping code for configurable e_r fields, and those can exist without e_r.module (just can't be created in Field UI, but can be shipped by profile / module config)

Proposed resolution

  1. Remove Drupal\entity_reference\ConfigurableEntityReferenceItem in favour of Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
  2. Move or merge Drupal\entity_reference\ConfigurableEntityReferenceItem methods into Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
  3. Move all functionality of entity_reference from the module into core or other appropriate core modules.
  4. Keep the module empty, disabled and hidden in codebase until 8.1.x when will be removed in #2552139: Remove entity_reference module from codebase.

Remaining tasks

- Needs framework manager review: http://cgit.drupalcode.org/drupal/tree/core/MAINTAINERS.txt means getting feedback from effulgentsia, catch, or alexpott
- Remove the empty entity_reference module from code base in 8.1.x, issue #2552139: Remove entity_reference module from codebase. Not before 9.x, we need to keep the module with the empty BC classes during the 8.x lifetime.

User interface changes

None.

API changes

  • A bunch of tests and modules won't have to depend on 'entity_reference' module anymore
  • Contrib modules that extend ConfigurableEntityReferenceItem will have to extend the base one instead

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it makes the core codebase more clear
Issue priority Major because removes an inconsistency that creates confusion.
Prioritized changes The main goal of this issue is moving code in the right place
Disruption Contrib modules that extend ConfigurableEntityReferenceItem will need to extend EntityReferenceItem instead. An upgrade path is required for existing configuration that depends on entity reference plugins.

Data model changes

CommentFileSizeAuthor
#189 interdiff.txt2.17 KBamateescu
#189 2429191-189.patch150.22 KBamateescu
#187 interdiff.txt782 bytesclaudiu.cristea
#187 deprecate-2429191-187.patch150.48 KBclaudiu.cristea
#183 2429191-183.patch150.09 KBclaudiu.cristea
#178 2429191-e_r_module-177.patch151.19 KByched
#175 interdiff.txt2.28 KByched
#175 2429191-e_r_module-173.patch154.89 KByched
#170 interdiff.txt5.53 KBclaudiu.cristea
#170 2429191-do-not-test.patch154.11 KBclaudiu.cristea
#160 interdiff.txt1.8 KByched
#160 2429191-e_r_module-159.patch154 KByched
#159 interdiff.txt16.89 KByched
#159 2429191-e_r_module-158.patch154.03 KByched
#154 interdiff.txt602 bytesclaudiu.cristea
#154 2429191-154.patch141.63 KBclaudiu.cristea
#137 interdiff.txt749 bytesclaudiu.cristea
#137 2429191-137.patch137.59 KBclaudiu.cristea
#131 interdiff.txt456 bytesclaudiu.cristea
#131 burn-2429191-131.patch136.86 KBclaudiu.cristea
#125 interdiff.txt474 bytesclaudiu.cristea
#125 2429191-125.patch136.85 KBclaudiu.cristea
#124 interdiff.txt1.88 KBclaudiu.cristea
#124 burn-2429191-124.patch136.87 KBclaudiu.cristea
#105 interdiff.txt2.3 KBclaudiu.cristea
#105 burn-2429191-105.patch122.57 KBclaudiu.cristea
#94 interdiff.txt3.15 KBclaudiu.cristea
#94 burn-2429191-94.patch122.93 KBclaudiu.cristea
#85 interdiff.txt31.19 KBclaudiu.cristea
#85 burn-2429191-85.patch122.64 KBclaudiu.cristea
#79 burn-2429191-79.patch115.96 KBclaudiu.cristea
#76 burn-2429191-76.patch115.96 KBclaudiu.cristea
#68 2429191-67.patch116.06 KBclaudiu.cristea
#66 burn-2429191-66.patch314.45 KBnlisgo
#62 interdiff.txt891 bytesclaudiu.cristea
#62 2429191-62.patch116.17 KBclaudiu.cristea
#60 burn-2429191-60.patch115.3 KBclaudiu.cristea
#57 interdiff.txt790 bytesclaudiu.cristea
#57 burn-2429191-57.patch308.07 KBclaudiu.cristea
#54 burn-2429191-54.patch114.58 KBclaudiu.cristea
#51 interdiff.txt596 bytesclaudiu.cristea
#51 burn-2429191-51.patch114.5 KBclaudiu.cristea
#47 interdiff.txt9.17 KBclaudiu.cristea
#47 burn-2429191-47.patch114.59 KBclaudiu.cristea
#40 burn-2429191-40.patch114.78 KBclaudiu.cristea
#34 burn-2429191-34.patch91 KBclaudiu.cristea
#34 interdiff.txt3.38 KBclaudiu.cristea
#32 interdiff.txt7.59 KBclaudiu.cristea
#32 burn-2429191-32.patch89.72 KBclaudiu.cristea
#30 interdiff.txt1.61 KBclaudiu.cristea
#30 burn-2429191-30.patch83.61 KBclaudiu.cristea
#28 interdiff.txt1.38 KBclaudiu.cristea
#28 2429191-28.patch82 KBclaudiu.cristea
#26 2429191-26.patch238.9 KBclaudiu.cristea
#24 burn-2429191-24.patch232.29 KBclaudiu.cristea
#20 interdiff.txt18.56 KBamateescu
#20 2429191-20.patch104.19 KBamateescu
#16 2429191-10.patch86.37 KBamateescu
#8 2429191-with-2436835.patch99.32 KBamateescu
#6 interdiff.txt368 bytesamateescu
#6 2429191-6.patch88.44 KBamateescu
#1 2429191.patch87.56 KBamateescu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amateescu’s picture

Status: Active » Needs review
FileSize
87.56 KB

RIP e_r.module, you will be missed!

Status: Needs review » Needs work

The last submitted patch, 1: 2429191.patch, failed testing.

jibran’s picture

Entity Reference module
- Amitai Burstein 'Amitaibu' http://drupal.org/user/57511
- Andrei Mateescu 'amateescu' http://drupal.org/user/729614

We can remove this too from MAINTAINERS.txt. :P

yched’s picture

OMG so much yay.

As a side note, though - ER is a topic in itself, it would be nice to keep an "entity reference field" or something in MAINTAINERS.txt, rather than simply merging it in the "field system" component.

yched’s picture

amateescu’s picture

Title: Burn entity_reference.module and spread its ashes all over core » Remove entity_reference.module and scatter its remains all over core
Status: Needs work » Needs review
FileSize
88.44 KB
368 bytes

Rerolled on top of #2436835-28: Unable to create config schema for entity type specific entity reference selection plugin. (which also needs a review :)). The schema fixes from that issue should also fix the failures here.

Also, less sensational 3AM issue title :/

Status: Needs review » Needs work

The last submitted patch, 6: 2429191-6.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
FileSize
99.32 KB

Heh, of course it doesn't apply, here's a combined patch.

Status: Needs review » Needs work

The last submitted patch, 8: 2429191-with-2436835.patch, failed testing.

Berdir’s picture

But...but... the old title was awesome ;)

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -91,8 +98,11 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
    -    if (isset($settings['target_bundle'])) {
    -      $properties['entity']->getTargetDefinition()->addConstraint('Bundle', $settings['target_bundle']);
    +    // @todo This is a problem, the target bundles is now a field setting
    +    // instead of a field storage setting. Clarify/fix this in
    +    // https://www.drupal.org/node/2064191
    +    if (isset($settings['handler_settings']['target_bundles'])) {
    +      $properties['entity']->getTargetDefinition()->addConstraint('Bundle', $settings['handler_settings']['target_bundles']);
         }
    

    See also the recent discussion in the remove taxonomy term reference field issue on field vs. storage setting.

  2. +++ b/core/modules/system/system.module
    @@ -1382,3 +1386,93 @@ function system_path_insert() {
    +
    +/**
    + * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
    + *
    + * Reset the instance handler settings, when the target type is changed.
    + */
    +function system_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
    +  if ($field_storage->getType() != 'entity_reference') {
    +    // Only act on entity reference fields.
    

    I'd argue this belongs in field.module, not system?

    The config entities are provided by field.module, not core.

  3. +++ b/core/modules/system/system.module
    @@ -1382,3 +1386,93 @@ function system_path_insert() {
    +function entity_reference_create_field($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
    

    This is exclusively used in tests. I don't think there's going to be enough code to dynamically create ER fields to keep this as a public API. Test trait?

  4. +++ b/core/modules/system/system.views.inc
    @@ -10,10 +10,19 @@
    -function entity_reference_field_views_data(FieldStorageConfigInterface $field_storage) {
    +function core_field_views_data(FieldStorageConfigInterface $field_storage) {
    

    That's.. weird ;) But same, why not move this to views.module?

andypost’s picture

amateescu’s picture

Title: Remove entity_reference.module and scatter its remains all over core » [PP-1] Remove entity_reference.module and scatter its remains all over core
Status: Needs work » Postponed
amateescu’s picture

alexpott’s picture

+++ b/core/modules/system/system.module
@@ -1382,3 +1386,93 @@ function system_path_insert() {
+/**
+ * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
+ *
+ * Reset the instance handler settings, when the target type is changed.
+ */
+function system_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
+  if ($field_storage->getType() != 'entity_reference') {
+    // Only act on entity reference fields.
+    return;
+  }
+
+  if ($field_storage->isSyncing()) {
+    // Don't change anything during a configuration sync.
+    return;
+  }
+
+  if ($field_storage->getSetting('target_type') == $field_storage->original->getSetting('target_type')) {
+    // Target type didn't change.
+    return;
+  }
+
+  foreach ($field_storage->getBundles() as $bundle) {
+    $field = FieldConfig::loadByName($field_storage->getTargetEntityTypeId(), $bundle, $field_storage->getName());
+    $field->settings['handler_settings'] = array();
+    $field->save();
+  }
+}

Is this code used? You can't change the the target_type through the UI. Shouldn't we just prevent changing it?

alexpott’s picture

Title: [PP-1] Remove entity_reference.module and scatter its remains all over core » Remove entity_reference.module and scatter its remains all over core
Status: Postponed » Needs work

The blocking issue has landed.

amateescu’s picture

Title: Remove entity_reference.module and scatter its remains all over core » Burn entity_reference.module and scatter its ashes all over core
FileSize
86.37 KB

Restoring the original titile.. by popular demand :D

#14, you can change the target type in the UI when the field doesn't have any data.

#10.1: Yep, that has to be dealt with at some point, that's why put a @todo with a pointer there.
#10.2: Addressed in this reroll. It was quite hard to reroll this on top of the recent changes so I can't provide an interdiff :/
#10.3: We now have a dedicated issue for that.
#10.4: Do you mean to just move the code but keep that function name? Because the provider for the ER field is still 'core' :)

This patch is rolled on top of #2452619: Move entity_reference_create_field function to EntityReferenceTestTrait so it won't apply until that issue gets in. Leaving at NW for this reason.

Berdir’s picture

10.4 yeah, I guess so. surprised that we have no other example yet with all the stuff we moved into core, but I guess all those field types didn't have special views integration. The only other option I see is to put it right into views_field_default_views_data(), which is always called. That might actually not be such a stupid idea?

Berdir’s picture

I guess the difference of that is that it would automatically also run for taxonomy, file/image and other references, that are not explicitly type entity_reference.

There's already an entity_reference_revisions module in contrib, which would then also benefit from it, although it would probably have to customize the relationship a bit.

yched’s picture

Oddities like core_field_views_data() are artifacts of the current shape of the "views integration for field types" API, which is still very much the CCK D6 version :-/. In an ideal world, it would move to an OO / handler shape, like was done for "views integration for entity types".
Separate issue, though ;-)

amateescu’s picture

Status: Needs review » Needs work

The last submitted patch, 20: 2429191-20.patch, failed testing.

jibran queued 20: 2429191-20.patch for re-testing.

The last submitted patch, 20: 2429191-20.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
232.29 KB

Let's see a simple reroll.

Status: Needs review » Needs work

The last submitted patch, 24: burn-2429191-24.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
238.9 KB

Sorry, forgot the new trait.

Status: Needs review » Needs work

The last submitted patch, 26: 2429191-26.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
82 KB
1.38 KB

Status: Needs review » Needs work

The last submitted patch, 28: 2429191-28.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
83.61 KB
1.61 KB

Status: Needs review » Needs work

The last submitted patch, 30: burn-2429191-30.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
89.72 KB
7.59 KB

Narrowing the test failures.

Status: Needs review » Needs work

The last submitted patch, 32: burn-2429191-32.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
3.38 KB
91 KB

Not ready. Still needs tests fixing.

Status: Needs review » Needs work

The last submitted patch, 34: burn-2429191-34.patch, failed testing.

amateescu’s picture

@claudiu.cristea, you can also use a patch testing issue for this, otherwise the issue becomes needlessly hard to scan for relevant comments :)

claudiu.cristea’s picture

Assigned: Unassigned » alexpott

Assigning this to @alexpott, CC @catch for a direction with this issue.

Few days ago, I discussed on IRC with @Berdir on this issue and he recommended me to ask you (@alexpott & @catch) if this can go in 8.0.0. There's some work to do here, not a simple issue, and I want to be sure that we don't waste effort on a task that has no chance to catch 8.0.0.

Overall, I feel that entity reference needs some love before the first 8 stable and I'm willing to help here. There are other unfinished tasks/bugs related to ER open.

webchick’s picture

Issue tags: +Needs beta evaluation

nice try.

alexpott’s picture

Assigned: alexpott » Unassigned
Issue tags: +Needs framework manager review

This can go in the framework manager review queue.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
114.78 KB

This has to be green.

Entity reference field (and descendants, like image, file) they all need an update path to remove the target_bundle setting from field storage config and possibly append it to field config handler settings, into target_bundles array. That's why I've implemented a new update hook, field_update_8001(), and added test to test this update (\Drupal\system\Tests\Field\Update\FieldSettingsTest).

Note also that Entity Reference module is still kept in code base but empty, with no functionality and we have to remove it in a separate issue. I will open a new issue for that.

claudiu.cristea’s picture

Opened #2552139: Remove entity_reference module from codebase to remove entity_reference module from codebase in 8.1.x.

cilefen’s picture

Can someone indicate in the beta evaluation which prioritized change type this is?:

https://www.drupal.org/core/beta-changes#prioritized

yched’s picture

Wondering about field_update_8001() :

  1. given that this patch is moving stuff from e_r.module to Core, doesn't it belong to system updates rather than field.module, who is not really involved here ?
  2. Do we really need to bother carrying the former storage 'target_bundle' over to the field handler_settings ? IIRC nothing was actually using that setting anyway for configurable fields, so whatever was in there was not really important ? (if the field was working as expected, the field handler_settings already has the correct target_bundles to make the field work ?)
  3. +++ b/core/modules/field/field.install
    @@ -0,0 +1,69 @@
    +  // Iterate on all fields storage to find fields having 'target_setting'.
    

    should be 'target_bundle' ?

  4. +++ b/core/modules/field/field.install
    @@ -0,0 +1,69 @@
    +          $handler_settings = $handler_settings ?: [];
    

    That line shouldn't be needed, the !empty() in the next line should account for the case $handler_settings is empty / NULL (empty($null['foo']) is TRUE)

  5. +++ b/core/modules/field/field.install
    @@ -0,0 +1,69 @@
    +          else {
    +            continue;
    +          }
    

    If the value is neither an array nor a string, then we'll be looping an all fields just to do "continue" on each one. This check (if needed at all ? can it really happen that it's not empty and neither an array nor a string ?) could move to the if() wrapping the foreach() ?

  6. +++ b/core/modules/field/field.install
    @@ -0,0 +1,69 @@
    +  // Disable 'entity_reference' module.
    +  $module_installer->uninstall(['entity_reference']);
    

    Not sure how we handle modules disappearing from the codebase, but AFAICT by looking at ModuleInstaller::uninstall(), this will do nothing if the module cannot be found in the codebase (first if() in the method)

    Shouldn't we just directly remove the entry from the core.extension config ?

claudiu.cristea’s picture

@yched,

Not sure how we handle modules disappearing from the codebase, but AFAICT by looking at ModuleInstaller::uninstall(), this will do nothing if the module cannot be found in the codebase (first if() in the method)

I don't think we can remove the module from codebase right now because there are update tests that have the module in the list and enabled (from D8 dumps) and those tests will crash because are not able to find the code in the code base. The patch is not removing the module, is only leaving an empty module with no functionality and disable it. Anyway, I'm not very sure that removing from core.extension will not work.

yched’s picture

Sure, but that's only because the #2552139: Remove entity_reference module from codebase part is temporarliy deferred to a later step ? Once that is done, sites going from beta14 to beta15 (or whatever depending on when this gets in) will run the update while e_r.module is not in the codebase anymore, and the code in the update as it currently stands will do nothing ?

Berdir’s picture

The problem is this:

Let's assume this scenario:

1. We commit this now including this upgrade path.
2. You run the updates to the next beta, the module is uninstalled and everything works.
3. Later on, lets say in 8.1, we remove the module left-overs from the system.

Now, someone, for some reason, updates a site directly from beta13 to 8.1. Then he will run into the same problem as we have right now.

That's the main reason for why update functions are so complex. You never know from which version someone is updated to what, they need to work for all possible cases. And the best way to do that is to work with as low-level API's as possible and avoid any hooks/events that you can't control.

That said, we actually discussed on the d8 criticals hangout last friday about exactly such a scenario: Whether we want to special case beta updates and not official support a direct update from betaX to 8.0+. This would be a good reason for that. At the same time, we're going to survive carrying around a hidden, empty entity_reference.info.yml file.

claudiu.cristea’s picture

FileSize
114.59 KB
9.17 KB

#43.1: Moved as system_update_8004().

#43.2-5: Removed the part that copies target_bundle over handler settings target_bundles.

#43.6, #45, #46: Using config API to uninstall.

Also in system_update_8004() I'm processing now module dependencies and type provider values.

Status: Needs review » Needs work

The last submitted patch, 47: burn-2429191-47.patch, failed testing.

claudiu.cristea’s picture

These tests are passing locally. I don't understand why are failing here.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
114.5 KB
596 bytes

Status: Needs review » Needs work

The last submitted patch, 51: burn-2429191-51.patch, failed testing.

claudiu.cristea’s picture

Reroll.

claudiu.cristea’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 54: burn-2429191-54.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
308.07 KB
790 bytes

Status: Needs review » Needs work

The last submitted patch, 57: burn-2429191-57.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
115.3 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 60: burn-2429191-60.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
116.17 KB
891 bytes

Fixed the new test location.

claudiu.cristea queued 62: 2429191-62.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 62: 2429191-62.patch, failed testing.

nlisgo’s picture

Assigned: Unassigned » nlisgo
Issue tags: +Needs reroll
nlisgo’s picture

Assigned: nlisgo » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
314.45 KB

Status: Needs review » Needs work

The last submitted patch, 66: burn-2429191-66.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
116.06 KB

The reroll is not straight. #66 doesn't take into account changes from 7a25f513f5b74d7fbc29b95b7de2fc88334533f4.

claudiu.cristea’s picture

Issue tags: +er revisit till rc

Tagging.

nlisgo’s picture

Thanks @claudiu.cristea I should have noticed that from the size of the patch.

claudiu.cristea’s picture

Issue tags: -er revisit till rc +ER check for RC

Fix tag.

yched’s picture

Status: Needs review » Needs work

Reopened #2064191: Fix the 'target_bundle' field setting - 'target_bundles' are not validated when entity_reference is enabled and posted a patch over there, to try to get that part cleaned up.

As I noted there, this part of the patch here is incorrect :

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
@@ -102,14 +108,11 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
-    if (isset($settings['target_bundle'])) {
-      $properties['entity']->addConstraint('Bundle', $settings['target_bundle']);
-      // Set any further bundle constraints on the target definition as well,
-      // such that it can derive more special data types if possible. For
-      // example, "entity:node:page" instead of "entity:node".
-      $properties['entity']->getTargetDefinition()
-        ->addConstraint('Bundle', $settings['target_bundle']);
+    if (!empty($settings['handler_settings']['target_bundles'])) {
+      $properties['entity']
+        ->addConstraint('Bundle', $settings['handler_settings']['target_bundles']);
     }

'handler_settings' is a Field-level setting, we can't access it in propertyDefinitions(), where all we have is a FieldStorageDefinition.

yched’s picture

That would be *very* nice to get this in before RC :-)
Now that #2064191: Fix the 'target_bundle' field setting - 'target_bundles' are not validated when entity_reference is enabled is in, that should be mostly about moving code around with no logic change, right ?

claudiu.cristea’s picture

@yched, I'll try to rework this tomorrow. It would be nice if we can have a positive sign on this from the core committers.

webchick’s picture

You still need a (actual) beta evaluation in order to get said sign-off.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
115.96 KB

here we go. Thank you @yched for hints.

Status: Needs review » Needs work

The last submitted patch, 76: burn-2429191-76.patch, failed testing.

jibran’s picture

Issue tags: +Needs reroll
claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
115.96 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 79: burn-2429191-79.patch, failed testing.

Status: Needs work » Needs review
claudiu.cristea’s picture

Issue summary: View changes

Fixed IS. Added Beta Evaluation.

yched’s picture

Thanks for the awesome work, @claudiu.cristea !

1st pass at reviewing, I only looked at the "peripherals" for now (not the actual e_r code being moved around)

  1. +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
    @@ -132,7 +133,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    -        '#element_validate' => array('_entity_reference_element_validate_filter'),
    +        '#element_validate' => array(array(get_class($this), 'elementValidateFilter')),
    
    @@ -179,7 +180,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    -        '#process' => array('_entity_reference_form_process_merge_parent'),
    +        '#process' => array(array('\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem', 'formProcessMergeParent')),
    

    Nit : move to [ ... ] short syntax ?

  2. +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
    @@ -215,6 +216,16 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
    +   * @todo Move some form of this to Form API itself?
    

    We shouldn't be adding orphaned @todos, we should either remove it or open an issue and link to it.

  3. +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
    @@ -338,8 +349,8 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
    -    // entity_reference_query_entity_reference_alter().
    -    $query->addTag('entity_reference');
    +    // system_query_entity_reference_selection_alter().
    +    $query->addTag('entity_reference_selection');
    

    Why is this change needed ? That seems like an API break ?

  4. +++ b/core/modules/migrate/src/Entity/MigrationInterface.php
    @@ -252,6 +252,8 @@ public function setProcess(array $process);
    +   *
    +   * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField().
    

    That looks unrelated ?

  5. +++ b/core/modules/system/src/Tests/Field/Update/FieldSettingsTest.php
    @@ -0,0 +1,101 @@
    +class FieldSettingsTest extends UpdatePathTestBase {
    

    Class name is a bit vague :-)

  6. +++ b/core/modules/system/src/Tests/Field/Update/FieldSettingsTest.php
    @@ -0,0 +1,101 @@
    +    // Create an entity reference field.
    +    $this->createEntityReferenceField('node', 'article', 'foo', $this->randomString(), 'node');
    +
    +    // Use the Config API in order to bypass validations and write directly to
    +    // the backend.
    +    $field_storage = $this->configFactory->getEditable('field.storage.node.foo');
    +    // Add a deprecated 'target_bundle' storage settings.
    +    $field_storage->set('settings.target_bundle', NULL);
    +    // Add a dependency to the 'entity_reference' module to check if it will get
    +    // removed.
    +    $dependencies = $field_storage->get('dependencies');
    +    $dependencies['module'][] = 'entity_reference';
    +    $field_storage->set('dependencies', $dependencies);
    +    // Set the provider to 'entity_reference' to see if it will get replaced
    +    // by 'core'.
    +    $field_storage->set('module', 'entity_reference');
    +    $field_storage->save(TRUE);
    

    As mentioned by @dawehner in #2064191-55: Fix the 'target_bundle' field setting - 'target_bundles' are not validated when entity_reference is enabled, the test shouldn't use the APIs to adjust the content of the config before running the updgrades.

    We should either
    - put our test fixtures in an additional dump file (like for example LocalActionsAndTasksConvertedIntoBlocksUpdateTest does),
    - or simply base our test on the content of drupal-8.bare.standard.php.gz (frozen dump based on beta12)

    The latter is way simpler and largely good enough IMO, that dump contains configurable e_r fields we can test (node.article.field_tags for example)

    See for example EntityReferenceTargetBundleUpdateTest

  7. +++ b/core/modules/system/src/Tests/Field/Update/FieldSettingsTest.php
    @@ -0,0 +1,101 @@
    +    // The legacy 'target_bundle' storage setting exists and is NULL.
    +    $this->assertTrue(array_key_exists('target_bundle', $settings));
    +    $this->assertNull($settings['target_bundle']);
    ...
    +    // Setting 'target_bundle' has been removed.
    +    $this->assertFalse(array_key_exists('target_bundle', $settings));
    

    After #2064191: Fix the 'target_bundle' field setting - 'target_bundles' are not validated when entity_reference is enabled, those parts are handled in a different update, and tested by a different test.

  8. +++ b/core/modules/system/system.install
    @@ -1808,5 +1808,44 @@ function system_update_8011() {
    +function system_update_8012() {
    

    Arguably this would belong to field.module :
    - e_r module was about configurable fields and required field.module
    - the update of the field config only makes sense if field.module is enabled

  9. +++ b/core/modules/system/system.module
    similarity index 83%
    rename from core/modules/entity_reference/entity_reference.views.inc
    
    rename from core/modules/entity_reference/entity_reference.views.inc
    rename to core/modules/system/system.views.inc
    

    Ideally that should be shipped in views.module instead of system.

  10. +++ b/core/modules/taxonomy/taxonomy.module
    @@ -501,9 +501,12 @@ function taxonomy_build_node_index($node) {
    +      $is_entity_reference_class = $class == $entity_reference_class || is_subclass_of($class, $entity_reference_class);
    

    Nit : would need parenthesis around the == check.
    (also, that would be best as === IMO)

  11. +++ b/core/modules/entity_reference/entity_reference.module
    @@ -2,212 +2,7 @@
    -      $output .= '<dt>' . t('Configuring form displays') . '</dt>';
    -      $output .= '<dd>' . t('Reference fields have several widgets available on the <em>Manage form display</em> page:');
    -      $output .= '<ul>';
    -      $output .= '<li>' . t('The <em>Check boxes/radio buttons</em> widget displays the existing entities for the entity type as check boxes or radio buttons based on the <em>Allowed number of values</em> set for the field.') . '</li>';
    -      $output .= '<li>' . t('The <em>Select list</em> widget displays the existing entities in a drop-down list or scrolling list box based on the <em>Allowed number of values</em> setting for the field.') . '</li>';
    -      $output .= '<li>' . t('The <em>Autocomplete</em> widget displays text fields in which users can type entity labels based on the <em>Allowed number of values</em>. The widget can be configured to display all entities that contain the typed characters or restricted to those starting with those characters.') . '</li>';
    -      $output .= '<li>' . t('The <em>Autocomplete (Tags style)</em> widget displays a multi-text field in which users can type in a comma-separated list of entity labels.') . '</li>';
    

    Those are not reflected in the help text added to field_help() ?

  12. +++ b/core/modules/field/field.module
    @@ -205,6 +218,67 @@ function field_entity_bundle_delete($entity_type, $bundle) {
    +function field_form_field_ui_field_storage_add_form_alter(array &$form) {
    

    Nit : would rather belong to field_ui.module ?

yched’s picture

Almost done, but need to run, here's what I have for a 2nd part :

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -164,6 +171,13 @@ public function getConstraints() {
    +    // Remove the 'AllowedValuesConstraint' validation constraint because entity
    +    // reference fields already use the 'ValidReference' constraint.
    +    foreach ($constraints as $key => $constraint) {
    +      if ($constraint instanceof AllowedValuesConstraint) {
    +        unset($constraints[$key]);
    +      }
    +    }
    

    Minor : this would logically go above the code block where we add another constraint (no need to loop over that one)

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -283,6 +297,107 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
    +  public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
    +    if ($form_state->hasValue('field')) {
    +      $form_state->unsetValue(array('field', 'settings', 'handler_submit'));
    +      $form_state->get('field')->settings = $form_state->getValue(['field', 'settings']);
    +
    +      $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($form_state->get('field'));
    +      $handler->validateConfigurationForm($form, $form_state);
    +    }
    +  }
    

    This method is faitly different from what it used to be in ConfigurableEntityReferenceItem, wondering why ?

  3. +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php
    @@ -39,7 +39,7 @@
    -  protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
    +  public function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
    

    Why the visibility change ?

  4. +++ b/core/modules/system/system.views.inc
    @@ -10,9 +10,19 @@
    +  // The code below only deals with the Entity reference field.
    

    Nitpick : s/field/field type

claudiu.cristea’s picture

FileSize
122.64 KB
31.19 KB
  • #83.1, 2: OK.
  • #83.3: I don't know what is the reason for that change. We should ask @amateescu, he worked the patch in the early stages. I switched back for now.
  • #83.4: Removed.
  • #83.5: I moved the test together with the one for filed_update_8001. I renamed the class to a generic FieldUpdateTest now we can add there future tests for field -- field_update_N()
  • #83.6: Ok, I used field_tags for testing. It works.
  • #83.7: Yep! I forgot that.
  • #83.8: Great to escape from system.install hell :)
  • #83.9: Moved in views.views.inc.
  • #83.10: Ok.
  • #83.11: Added.
  • #83.12: Moved to field ui.
  • #84.1: Ok.
  • #83.2: I did some tests around this. It seems that is an attempt clear non-JS submit button that is stored in settings. But as far as I can see that if () {} is never triggered and the settings are saved correctly. Reverted to ConfigurableEntityReferenceItem version because that is in place right now and works as expected. Maybe @amateescu knows more on this.
  • #84.3: That is a mistake. Reverted.
  • #84.4: Ok.

Status: Needs review » Needs work

The last submitted patch, 85: burn-2429191-85.patch, failed testing.

yched’s picture

@claudiu.cristea : Thanks !

Meanwhile, I finished reviewing #79, no remarks left :-)

Remarks below are about the interdiff in #85

  1. +++ b/core/modules/views/views.views.inc
    @@ -652,3 +652,76 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
    +function views_field_views_data(FieldStorageConfigInterface $field_storage) {
    

    It still needs to be called core_field_default_views_data(), since it's a "pseudo-hook / magic callback" (probably one of the last in core), called on the provider of the field type - in this case, 'core'.

    Still makes sense IMO that views.module's views.views.inc provides integration code for the field types provided by core.

    That probably explains the fails.

  2. +++ b/core/modules/field/src/Tests/Update/FieldUpdateTest.php
    @@ -0,0 +1,103 @@
    +    // The type provider for the field_tags field is entity_reference module.
    ...
    +    // The entity_reference module is a dependency of field_tags config entity.
    ...
    +    // Check the 'node.article.field_tags' field config.
    ...
    +    // The type provider is now 'core'.
    ...
    +    // The module dependency on 'entity_reference' has been removed.
    ...
    +    // The entity_reference module has been uninstalled.
    

    Clarity nitpick : can we start those comments with "Check that [foo is bar]" ? Helps a lot when visually parsing what the test does :-)

yched’s picture

Then I guess the last question is : at this point, what prevents us from removing entity_ref.module completely ? :-)

Also, @amateescu :
The review points in #83.3 and #84.2 seem to be about your earlier versions of the patch. @claudiu.cristea reverted them in #85, but maybe we missed something ?

yched’s picture

Issue summary: View changes

Expanded the motivations in the IS a bit.

klausi’s picture

Great, I love the idea that we can get rid of entityreference module!

+++ /dev/null
index 332de7b..0000000
--- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php

--- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php
+++ /dev/null

+++ /dev/null
+++ /dev/null
@@ -1,224 +0,0 @@

@@ -1,224 +0,0 @@
-<?php

Since we are in API freeze we cannot just remove classes like this, since that would break contrib modules. This class and all others from entityreference module need to stay as empty classes that just extend the one from Core now. Except for test classes.

And even in 8.1.x we cannot remove those classes, so the entire removal of the module must be postponed to Drupal 9. Otherwise we make contrib developers very angry :-)

jibran’s picture

@klausi that is why it has Needs framework manager review tag :). I think @Berdir has a script which renames the module so that can be helpful here but none the less good points.

As DER maintainer this is disruptive but I only have to change some use statements and it'll be good as new :D.

I'm strongly +1 for this issue.

yched’s picture

@klausi : thing is, we cannot keep the class for BC without also keeping an entity_reference.module that can be enabled (for the class to be found by the autoloader)

Since we wouldn't want people to see it in the module admin page and wonder what it does (it does nothing), that would mean making it hidden *and* required.

The last submitted patch, 85: burn-2429191-85.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
122.93 KB
3.15 KB
  • #87.1: Right. I was confused by the docblock: "Implements hook_..." and treated as a hook, but it's a magic call. Expanding a little the docblock to explain this.
  • #87.2: Ok.
claudiu.cristea’s picture

@yched,

Then I guess the last question is : at this point, what prevents us from removing entity_ref.module completely ? :-)

I tried this once. All the update tests will fail because you import a DB snapshot of beta12 and inside that a Drupal instance where the entity_reference module is enabled. But in the same time the module is missing from the codebase. That shows a very angry drupal_get_filename() :)

trigger_error(SafeMarkup::format('The following @type is missing from the file system: @name', array('@type' => $type, '@name' => $name)), E_USER_WARNING);

Status: Needs review » Needs work

The last submitted patch, 94: burn-2429191-94.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review

The old bot :(

Berdir’s picture

Yes, removing the module is painful for existing sites.

I don't think we need to make the module required, just keep it around as hidden so that existing sites don't break.

claudiu.cristea’s picture

yched’s picture

I don't think we need to make the module required, just keep it around as hidden so that existing sites don't break.

That was if we wanted to keep the Item class for BC (if we keep the module anyway, we might as well do that ?). If a contrib module uses the class (and thus requires the module), but the module is hidden, you're in a deadlock ?

Thus I was thinking hidden + required (always enabled, problem disappears) ?

catch’s picture

If it's hidden and a dependency I'd expect core to enable it? If that doesn't work would be a bug.

Only thing you can't easily do when it's hidden is uninstall.

yched’s picture

Indeed, my bad, you can enable a module that depends on a hidden module, both through admin/modules and drush en.

So I guess that means we should just :
- leave reference/src/ConfigurableEntityReferenceItem.php as an empty @deprecated class extending EntityReferenceItem,
- remove the part of the update (and test) that uninstalls entity_reference.module on existing sites
- Adjust the 'description' in entity_reference.info.yml to something like "Deprecated, all functionality has been moved to Core' (because the current description, 'Provides a field that can reference other entities', would be a lie)
- (Not sure we really need the .module file ?)

And then we can RTBC, commit, and break no BC at all ? :-)

claudiu.cristea’s picture

@yched, sounds like plan. But still keep it as hidden: true, right? Anyway, if a site admin will disable the module we assume that he knows what he is doing, meaning he has no class extending ConfigurableEntityReferenceItem. Fair enough.

claudiu.cristea’s picture

FileSize
122.57 KB
2.3 KB

OK. That's it.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @claudiu.cristea. Let's do this !

klausi’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/MAINTAINERS.txt
    @@ -323,10 +323,6 @@ Email module
    -- Amitai Burstein 'Amitaibu' https://www.drupal.org/u/amitaibu
    -- Andrei Mateescu 'amateescu' https://www.drupal.org/u/amateescu
    

    I don't think we should remove amitaibu and amateescu, they should be moved either to the Entity API section or a new section "Entity Reference API".

  2. +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
    @@ -179,7 +180,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    +        '#process' => [['\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem', 'formProcessMergeParent']],
    

    since we depend on PHP 5.5 now we should use ::class here instead of the class name in a string.

  3. +++ /dev/null
    index 332de7b..0000000
    --- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php
    +++ /dev/null
    

    so this class should stay as empty BC class?

  4. +++ b/core/modules/field/field.install
    @@ -26,3 +26,43 @@ function field_update_8001() {
    +  $item_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
    

    can use ::class

So the patch still removes ConfigurableEntityReferenceItem, which we should not do. Let's make it @deprecated extending the Core one and otherwise empty.

I think we should also keep the plugin classes in src/Plugin for the Views integration stuff, with the same @deprecated pattern. We need to stop removing classes and leave them as empty @depreacted wrappers to keep the promise of not breaking contrib code.

claudiu.cristea’s picture

So the patch still removes ConfigurableEntityReferenceItem, which we should not do. Let's make it @deprecated extending the Core one and otherwise empty.

Ouch! That was a mistake on my side when I built the patch. Sorry.

YesCT’s picture

related to critical #2520526: Calculate configuration entity dependencies on install

there is a beta evaluation, so removing that tag

@claudiu.cristea does that mean you are working on it? if not, I can. (I'm pingable in IRC.)

YesCT’s picture

Issue summary: View changes

adding
Needs framework manager review: http://cgit.drupalcode.org/drupal/tree/core/MAINTAINERS.txt means getting feedback from effulgentsia, catch, or alexpott
to the remaining tasks in the issue summary, for clarity.

yched’s picture

@klausi :

#107.1 : MAINTAINERS.txt is a tough issue :-) Most of the entity_ref feature is already provided in Core/Field anyway, and Field is the only "component". There is no 'EntityReference" component (not technically in Core, and not in the list of "compnents" in issues).

Like with all the previous field types that were moved from modules to Core/File, this has the drawback of munging the issues under the "Field system" compnent, and making Field API maintainers the only apparent maintainers for them (which, personnaly, doesn't rejoice me ;-)).

But that is an existing issue (there's an issue open for this, can't find it atm), and given the timeframe, I'd rather not derail the patch on this. Also, in this case, it so happens that @amateescu is already a Field API maintainer, and that AFAIK @amitaibu has not really been involved with e_r after the initial patch :-)

So maybe can we punt on that ?

#107.2 .4: Wasn't aware of ::class. So those would become
'#process' => [[EntityReferenceItem::class, 'formProcessMergeParent']]
$item_class = EntityReferenceItem::class;
?
Why not, more readable indeed :-) Let's not block too much on those, though, there are many similar instances in core, and we can mass-simplify them later with a full search on '\Drupal\.*'

#107.3 : ConfigurableEntityReferenceItem - Oops, I was too quick when reviewing the interdiff #105 :-(

yched’s picture

Issue summary: View changes

Removed the "Remaining task : remove the empty entity_reference.module" item from the IS

yched’s picture

And agreed with @klausi #107 : "keep the plugin classes in src/Plugin for the Views integration stuff, with the same @deprecated pattern". Sucks, but that's the deal.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Working on it.

YesCT’s picture

@yched
@alexpott added the tag in #39, I was putting it in the summary so we didn't forget about it.

[edit:]
ahh, the third papraphragh in #111 is reinforcing that it is ok to remove the section in maintainers. I see.

yched’s picture

@YesCT : sure, I didn't modify that :-)

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
137.97 KB
7.84 KB

Note on views plugins: I renamed the deprecated plugins annotation labels to mark the also as deprecated. But I admit that I don't understand what happens if two modules are providing the same plugin type and id. And this is the case here, where we want to use those from Views for new views.

klausi’s picture

Status: Needs review » Needs work

We can't have two plugin classes with the same plugin ID annotation. The annotation should now be provided by the plugin class in Views only. Just keep the empty class around with the @deprecated note.

We have a change here which we cannot avoid: the Views style plugin class for the "entity_reference" plugin is changed. I think that is ok, modules should not hard-code anything to the specific class of a plugin. As long as we keep the old class around we keep compatibility with all modules that specifically extended that class or used it in other ways.

Almost there claudiu :-)

yched’s picture

+1, the real plugin implementations seen by the system are the new ones, the old classes don't provide plugins anymore, they are just empty shells kept there for contrib modules that might be extending from them for their own plugins,

Also, grammar in the @deprecated comments is a bit off :
"Use the [New\Classname] instead for extending from the [thing]."
Maybe just "Use [new class] instead." ?

The last submitted patch, 117: burn-2429191-116.patch, failed testing.

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Needs work » Needs review
FileSize
137.19 KB
4.5 KB
Wim Leers’s picture

Addressed all of @klausi's feedback, with one exception:

I think we should also keep the plugin classes in src/Plugin for the Views integration stuff, with the same @deprecated pattern. We need to stop removing classes and leave them as empty @depreacted wrappers to keep the promise of not breaking contrib code.

I don't think we can keep those because the plugin IDs would conflict. I'll leave that to you guys to sort out.

EDIT: ugh, cross-posted :/. Dropped the patch I was uploading, since Claudiu also made additional changes. I caught the problem @klausi pointed out in #118 early as you can see above :)

EDIT: DOUBLE cross-post. Drupal.org, you're super annoying in how incredibly bad you are at resolving cross-posts automatically. Complaining about the file field even after I've already removed them. Gahhhhhhhh.

claudiu.cristea’s picture

+++ b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php
@@ -7,218 +7,14 @@
+ * @deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.x. Use
+ *  \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem instead.

Can this be fixed on commit? An indent space is missed on the 2nd line :)

claudiu.cristea’s picture

FileSize
136.87 KB
1.88 KB

Hmm... other fixes.

claudiu.cristea’s picture

FileSize
136.85 KB
474 bytes

One more catch.

The last submitted patch, 124: burn-2429191-124.patch, failed testing.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Thanks !

Nitpick, can be fixed on commit :

+++ b/core/modules/field/field.install
@@ -29,7 +29,7 @@ function field_update_8001() {
+/**
+ * Fixes the entity reference fields storage type provider.
+ */
+function field_update_8002() {

A bit cryptic (and it's "field type provider" rather than "field storage type provide", which is not really a thing).
Could be simply : "The 'entity_reference' field type is now provided by core." ?

Other than that, yay, back to RTBC if green ?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 125: 2429191-125.patch, failed testing.

The last submitted patch, 121: burn-2429191-121.patch, failed testing.

yched queued 125: 2429191-125.patch for re-testing.

claudiu.cristea’s picture

FileSize
136.86 KB
456 bytes

@yched, thank you for the great review and guidance.

Fixed the 8002 docblock.

claudiu.cristea’s picture

Status: Needs work » Needs review
YesCT’s picture

so the bot runs. [edit: cross post]

The last submitted patch, 125: 2429191-125.patch, failed testing.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 131: burn-2429191-131.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
137.59 KB
749 bytes

HEAD has changed.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
amitaibu’s picture

Got a ping from @YesCT about this:

> and that AFAIK @amitaibu has not really been involved with e_r after the initial patch :-)

Indeed. As much as I like the idea of having my name in maintainers.txt, I wasn't involved in recent couple of years in ER, so feel free to remove me from there. I'll take credit for the initial ER patches in other occasions ;) Thanks for your hard work folks!

catch’s picture

Given there's a bc layer is this feasible for a minor version?

claudiu.cristea’s picture

@catch, I don't know if we want to go in the stable version with this solution where parts of entity reference are all around.

nlisgo’s picture

Feel free to remove my name from the credit list. My only involvement was an attempt at a reroll at #66. My reroll was unsuccessful.

Great work guys!

xjm’s picture

Title: Burn entity_reference.module and scatter its ashes all over core » Deprecate entity_reference.module and move its functionality to core
Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Postponed
Issue tags: -Needs framework manager review +minor version target

Discussed with @alexpott. Thanks for your work on this change! We definitely see the benefits of this change (better developer and site builder experience, less code to maintain, etc.). The fact that the patch retains BC also means that we could make this change now or in a minor version.

However, there are a number of risks with this change:

  • There is a lot of reshuffling of plugin and config dependencies needed for the change. Existing configuration on existing sites would have stale dependency references, and so would need an upgrade path.
  • The plugin, config, and module dependency changes also each increase the risk of exposing sites to other problems or bugs with dependency management.
  • The field_update_8002() in the patch addresses dependencies in fields, but not in views.

For these reasons, I think this change would need an additional upgrade path and upgrade path test, and manual testing of the upgrade path with various installed schema versions and ER-dependent content and configuration. Even then, there would still be a risk of introducing upgrade path bugs that caused problems between earlier betas, beta16, and RC1. Given how close we currently are to a release candidate and that we already have had numerous bugs related to both upgrade paths for these sorts of changes and for configuration dependencies in general, we think that the risk of making this change at this point in 8.0.x is unfortunately too high.

I'd suggest that we add some documentation to the codebase and UI about the state of the module for 8.0.x (could be an rc target issue). @alexpott and I agreed that we should then pursue this change in 8.1.x, once we've had more opportunity to discover and resolve issues related to these sorts of upgrade paths and also more time to write and test the upgrade path for this change in particular.

Also retitling, since the current title (while amusing and quite searchable) is not specific and a bit, um, incendiary.

Thanks everyone! And thanks @alexpott for helping review the changes in the patch and this comment.

yched’s picture

@catch: +1 to what @claudiu.cristea said. Removing the arbitray separation (Core has a full fledged e_r field, but you need an optional module that swaps the implemenation to be able to use it in Field UI) asap would really help cleanup unnecessary config dependencies before they spread all over (see #2520526: Calculate configuration entity dependencies on install that fixes places where they currently miss. Not having to deal with them while we don't actually need that would definitely be simpler)

Also, the current situation is pretty misleading because you *can* actually have configurable e_r fields without e_r.module (through the API or a module's config/default - just you cant use Field UI). So even the simple "e_r.module is for configurable e_r fields" assessment is actually an oversimplifiication that can lead to wrong assumptions and buggy code.

In short : still really in favor of doing this for 8.0.0 :-)

yched’s picture

Oops - #144 was a reply to @catch #140, crossposted with @xjm #143. Reading.

yched’s picture

Aw. Really sad that we have to keep this confusion, for the reasons explained in #144 :-(

At any rate, if this doesn't get in 8.0.0, we really need to get #2578249: Some e_r fields get the wrong Selection handler committed (fixes a nasty example of the "you can have configurable e_r fields without e_r.module" confusion I mentioned)

yched’s picture

Status: Postponed » Reviewed & tested by the community
Issue tags: +Needs framework manager review

Also : this argument from #143 is actually incorrect :

The field_update_8002() in the patch addresses dependencies in fields, but not in views

The update removes 'entity_ref' as a dependency in *all* config records (fields, views, entity displays, ... whatever else). That's easy, and cannot really lead to more bugs down the road : entity_ref.module is just en empty shell, no-one, ever, has any reason to ever depend on it. Thus IMO the other arguments (might break more things with dependencies down the road) are kind of invalid as well IMO ?

If the premises for the decision in #143 are incorrect, any chance we can reconsider ?

Temptatively setting back to RTBC and "Needs framework manager review". Sorry for the trouble, feel free to kick back if need be.

jibran’s picture

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

I agree 100% with @yched. I think framework manager should revisit the decision in the light of #147. @yched counter every point made in #143.

Thanks @amitaibu for all your work and once again thank you for your initial ER port you are awesome see you in OG issue queue fighting with ER modules shortcoming ;-)

xjm’s picture

+++ b/core/modules/field/field.install
@@ -20,9 +21,48 @@ function field_update_8001() {
+/**
+ * The 'entity_reference' field type is now provided by core.
+ */
+function field_update_8002() {
+  $config_factory = \Drupal::configFactory();
+  /** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
+  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
+
+  // Iterate on all configuration entities.
+  foreach ($config_factory->listAll() as $id) {
+    $changed = FALSE;
+    $config = $config_factory->getEditable($id);
+
+    // Update field storage configurations.
+    if (strpos($id, 'field.storage.') === 0) {
+      $class = $field_type_manager->getPluginClass($config->get('type'));
+      // Deal only with entity reference fields and descendants.
+      if ($class == EntityReferenceItem::class || is_subclass_of($class, EntityReferenceItem::class)) {
+        // Fix the type provider.
+        $config->set('module', 'core');
+        $changed = TRUE;
+      }
+    }
+
+    // Remove entity_reference module dependency from any configuration entity.
+    if ($dependencies = $config->get('dependencies.module')) {
+      if (($delta = array_search('entity_reference', $dependencies)) !== FALSE) {
+        unset($dependencies[$delta]);
+        $config->set('dependencies.module', $dependencies);
+        $changed = TRUE;
+      }
+    }
+
+    if ($changed) {
+      $config->save(TRUE);
+    }
+  }
+}

Here is the full update hook, for reference.

xjm’s picture

Thus IMO the other arguments (might break more things with dependencies down the road) are kind of invalid as well IMO ?

I disagree; that's not what #143 said. The point is that this change is not risk-free for existing sites, and we have very little time to make the change before RC or to find unexpected repercussions without risk to the RC upgrade path. I'm not saying it's clear-cut -- just that both the benefit and risk are high, which is why @alexpott and I discussed erring on the side of caution.

The point about this causing other dependency issues is worth considering, but I'm not sure it outweighs the risk.

I still don't see how Views ER plugin configuration dependencies are going to get removed in #149. I see it removing module dependencies and updating field storage dependencies.

yched’s picture

@xjm : the views plugins impacted are a display, row and style plugin, used by a very specific feature of (Core) e_r fields : the ViewsSelection handler, that lets you define referenceable entities by a view rather than by bundles.

Those plugin implementations are moved, but the plugin IDs remain unchanged. So I don't think anything in existing views config records need to be changed ? (other than, no longer needs e_r.module, which the update does)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I missed the part of the update where all configs which depend on entity reference are being updated.

+++ b/core/modules/field/field.install
@@ -20,9 +21,48 @@ function field_update_8001() {
+        unset($dependencies[$delta]);
+        $config->set('dependencies.module', $dependencies);

This needs to be $config->set('dependencies.module', array_values($dependencies)); otherwise some odd numbers are going to start appearing in config dependency keys.

Have we got test coverage of a view that depends on entity reference being updated... it would be great if this view also depended on user so we can test for the bug avoided by doing the array_values() above.

I still agree with @xjm that this is risky.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea
claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
141.63 KB
602 bytes

Rerolled and added #152.

claudiu.cristea’s picture

Assigned: claudiu.cristea » yched

Passing for review.

Status: Needs review » Needs work

The last submitted patch, 154: 2429191-154.patch, failed testing.

claudiu.cristea’s picture

Ouch, DrupalCI is lying. That should have failed. Opened a critical #2580293: Patch having test with "PHP Fatal error" is marked as PASSED.

nlisgo’s picture

+++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
@@ -10,7 +10,7 @@
+use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait ;

There are a few instances of a space before the semi-colon.

I have found 8.

yched’s picture

Status: Needs work » Needs review
FileSize
154.03 KB
16.89 KB

- Enriched testFieldUpdate8002() with tests for a view using the e_r plugins, checking that the "referenceable entities based on a view" feature still works
- Moved EntityReferenceSettingsTest, that got added ine_r.module meanwhile.

yched’s picture

Meh. Didn't intend to leave testFieldUpdate8001() commented out :-/

The last submitted patch, 159: 2429191-e_r_module-158.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 160: 2429191-e_r_module-159.patch, failed testing.

The last submitted patch, 160: 2429191-e_r_module-159.patch, failed testing.

The last submitted patch, 159: 2429191-e_r_module-158.patch, failed testing.

claudiu.cristea’s picture

Assigned: yched » claudiu.cristea
yched’s picture

Those fails beat me. The field.storage.node.field_ref_views_select_2429191.yml I provide as a fixture causes a schema error when the recently added field_post_update_save_custom_storage_property() tries to resave it -" Exception thrown while performing a schema update. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException()"

Same error if I completely comment out the field_update_8002() update we're adding here, so it's not the fault of the code in there.

Have to run, hope @claudiu.cristea can find out more :-/

yched’s picture

BTW, unrelated to the fails, but to leave clean dependencies, field_update_8002() should rather do

-        $config->set('dependencies.module', array_values($dependencies));
+        if ($dependencies) {
+          $config->set('dependencies.module', array_values($dependencies));
+        }
+        else {
+          $config->clear('dependencies.module');
+        }

We should roll that in the next patch.

yched’s picture

Other than those weird fails, the asserts about the view still working do pass, btw. It's just the post_update that chokes on my test field...

claudiu.cristea’s picture

It's something related to field_post_update_save_custom_storage_property()

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
FileSize
154.11 KB
5.53 KB

Just posting the progress including #158 and #167. Thank you @nlisgo for those findings.

yched’s picture

Aw. That's because the db created by our fixture file, drupal-8.views_entity_reference_plugins-2429191.php, also needs to contain entries describing the "schema" in the entity.storage_schema.sql k/v store. Kind of a massive drag :-/

Will try to add that.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Let me try, so that you can review.

claudiu.cristea’s picture

Assigned: claudiu.cristea » yched
Status: Needs work » Needs review
FileSize
156.67 KB
3.06 KB

I did that. Maybe I'm wrong somewhere because still fails :(

Status: Needs review » Needs work

The last submitted patch, 173: 2429191-173.patch, failed testing.

yched’s picture

Assigned: yched » Unassigned
Status: Needs work » Needs review
FileSize
154.89 KB
2.28 KB

OK, that was hell to debug, but the answer was : the fixture also needs to update the "last installed field storage" entry in k/v, otherwise
$field_storage->save() in field_post_update_save_custom_storage_property() will cascade down to SqlContentEntityStorageSchema::updateDedicatedTableSchema() thinking it's a deleted field.

This makes it fairly hard to provide fixtures with fields for update tests...
But well, this should be green.

The fact that views using the plugins provided formerly provided by e_r.module still work after the update is tested in FieldUpdateTest::testFieldUpdate8002()

yched’s picture

Oops, forgot to mention : interdiff #175 is with #170, I left patch #173 aside.

The last submitted patch, 173: 2429191-173.patch, failed testing.

yched’s picture

Reroll after #2578249: Some e_r fields get the wrong Selection handler, that already had to move entity_reference_field_config_update() and entity_reference_field_storage_config_presave() into field.module.

The last submitted patch, 175: 2429191-e_r_module-173.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 178: 2429191-e_r_module-177.patch, failed testing.

Status: Needs work » Needs review
jibran’s picture

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
@@ -393,4 +507,143 @@ public static function onDependencyRemoval(FieldDefinitionInterface $field_defin
+   * (i.e. 'handler_settings') up a level for easier processing by the validation

more then 80 chars?

claudiu.cristea’s picture

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Let's fix this before RC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 183: 2429191-183.patch, failed testing.

The last submitted patch, 183: 2429191-183.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
150.48 KB
782 bytes

Forgot a use statement.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Doh!!!

amateescu’s picture

I reviewed the latest patch and I could only find a small problem in the update function: we don't want to update the module of every field type that extends the EntityReferenceItem class, we only need to do it for the 'entity_reference' type :)

As one of the maintainers of this code in D8, I believe that the problems/motivation described in the current issue summary are very real and will cause a great deal of WTFs along with unnecessary future maintenance cost.

Given that the concerns raised in the initial framework/release manager review have been addressed and additional test coverage was added, the benefits of this patch are higher than the risk, IMHO.

  • alexpott committed 97823b5 on 8.0.x
    Issue #2429191 by claudiu.cristea, amateescu, yched, nlisgo, Berdir,...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Discussed with @xjm and @catch. We agreed with @amateescu that doing this now is less risky than trying this in 8.1 or 8.2 and that now we have the extra test coverage around the upgrade path the patch is also less risky to do. Whilst we are in the pre-RC commit freeze maintainers still have discretion therefore committing under that.

Committed 97823b5 and pushed to 8.0.x. Thanks!

amateescu’s picture

Thank you!!

I'm not sure if a change notice is needed since we kept everything needed for BC, but it's probably worth a bit of attention for existing D8 sites so I'll write one tonight if no one beats me to it.

yched’s picture

Awesome !!! Thanks all :-)

jibran’s picture

Yay!!! Seems like perfect story we added ER and kind of removed at the same time in Drupal 8.

Wim Leers’s picture

#194: haha :D

claudiu.cristea’s picture

Great! Thank you @yched, @amateescu, @jibran for not giving up. Also, many thanks to core committers for their decision.

yched’s picture

@jibran : entity_reference was moved to core, and then it was moved to Core.

fago’s picture

Wohoo, great!

>Yay!!! Seems like perfect story we added ER and kind of removed at the same time in Drupal 8.
We did even worse things to entity module ;)

claudiu.cristea’s picture

@jibran, @yched, @fago,

Lucky that Drupal 8 has the longest release cycle ever. We have time to move it back to contrib. LOL :D

The last submitted patch, 154: 2429191-154.patch, failed testing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

amateescu’s picture

Here's the change record: https://www.drupal.org/node/2598002

yched’s picture

Thanks @amateescu : adjusted "classes will be removed in 8.1.0" to "... in Drupal 9", since that's what we wrote in the code (and I don't think we plan on removing deprecated things in minor releases ?)

amateescu’s picture

Oh, right. Thanks for catching that :)

xjm’s picture