Problem/Motivation

Proposed resolution

Remaining tasks

 

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions
Update the issue summary noting if allowed during the beta Instructions
Draft a change record for the API changes Instructions

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

Priority: Major » Critical

I don't know how much of this qualifies as critical, but setting it as such for now, because this seems like too much fragility for something as fundamental as the site's data model.

Berdir’s picture

effulgentsia’s picture

Issue tags: +API change
xjm’s picture

Priority: Critical » Major

Discussed with @effulgentsia and @alexpott. This is definitely buggy (@effulgentsia pointed out that we have an invalid code example for hook_entity_base_field_info_alter() in entity.api.php even), but the actual functional failures are likely edgecases that have workarounds, so this shouldn't block the release of Drupal 8.0.0.

heddn’s picture

This is still a major issue for all the reasons in #4. But it needs a beta eval and some architectural insight.

Also tagging as related: #2225961: Introduce "controlled" setters on FieldDefinitionInterface to avoid special-casing FieldDefinition

heddn’s picture

Issue summary: View changes
heddn’s picture

Issue tags: +Needs beta evaluation
tim.plunkett’s picture

We still have in-code @todos pointing to #2225961: Introduce "controlled" setters on FieldDefinitionInterface to avoid special-casing FieldDefinition, which is marked as a dupe of this. Just FYI.

dawehner’s picture

Can't you copy an existing one and recreate one?

chx’s picture

For that we would need something like a toArray that you can pass to a factory to facilitate an easier copying.

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.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

tstoeckler’s picture

Priority: Major » Normal
Issue tags: -Needs beta evaluation

Discussed this today with @xjm, @plach, @amateescu and @Berdir and we agreed to downgrade this. There is no functional bug that has been pointed out here, nothing that is actually known not to work, neither in core or in contrib. So we should definitely fix this in some way, but the objects that you get passed do actually have various methods that you need, it's just not typehinted.

We also explicitly agreed that this would be re-raised to major if someone can point out a case where something is being passed that actually does not have the proper methods that you need.

Oh, I think this no longer needs a beta evaluation, by the way ;-)

tstoeckler’s picture

Issue tags: +DevDaysSeville

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

apaderno’s picture

Title: hook_entity_base_field_info_alter() implementations can't do their job on the interface they receive » hook_entity_base_field_info_alter() and hook_entity_bundle_field_info_alter() are documented to get a parameter that doesn't implement an interface with setter methods
Version: 8.4.x-dev » 8.5.x-dev
Issue summary: View changes
apaderno’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sam152’s picture

These kind of issues are quite complex to unpick, I think it would almost be worth dealing with them in two separate issues. Trying to tackle base fields first.

Reading over the implementation of EntityFieldManager::buildBaseFieldDefinitions, things happen in roughly this order:

  • $entity_class::baseFieldDefinitions is invoked to get the initial list of fields (this hints FieldDefinitionInterface).
  • Some additional fields are added depending on the circumstances.
  • entity_base_field_info is invoked (also hints FieldDefinitionInterface).
  • entity_base_field_info_alter is invoked (also hints FieldDefinitionInterface).

Here is my analysis of what the current state of this issue is:

  • Right now core seems to only require FieldDefinitionInterface, it doesn't assume BaseFieldDefinition outside of a bug in some documentation.
  • In reality, developers expect a BaseFieldDefinition because that's what everything uses at the moment.
  • There would be nothing stopping me from creating an implementation of FieldDefinitionInterface that had no setters, except that alter hook implementations would be left scratching their head.

I don't believe any of the alter hooks are any less useful hinting FieldDefinitionInterface interface. You are still completely able to replace the implementation of a field using setters in an API way like so:

  $fields['altered_field'] = BaseFieldDefinition::create($fields['altered_field']->getType())->...

Perhaps the issue should be to fix all documentation to make it clear an implementation of FieldDefinitionInterface is the ONLY thing required to define a base field and that the interface is what should be expected during alterations.

BaseFieldDefinition::createFromFieldStorageDefinition exists as a helper to create base fields from storage definitions. Perhaps we could create the same thing for FieldDefinitionInterface. However, given how there aren't many concrete examples of people actually using this flexibility, it might not be worth it.

The "special casing" in EntityFieldManager seems like it's mostly providing some defaults to BaseFieldDefinitions. I think that's a good enough reason by itself to add setters to the interface, given I don't think it's known yet that an alternative implementation would require such defaults in the first place.

Sam152’s picture

Status: Active » Needs review
FileSize
10.36 KB

So here is a proof of concept for essentially a "wont fix" approach.

The alternative I see is extra setters on FieldDefinitionInterface but that could possibly compromise the flexibility of fields coming from a source this is completely immutable. A field definition could start its life out as an instance of CantBeChangedFieldDefinition and something could replace it with an instance of FancyMutableBaseField and while they are both implementing FieldDefinitionInterface (and other code expects this), things could continue to work.

+++ b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php
@@ -33,6 +33,11 @@
+   * If you return fields as an instance of BaseFieldDefinition, the field name,
+   * target entity type ID and provider will be set automatically. If some other
+   * implementation of FieldDefinitionInterface is returned, this information
+   * must be explicitly available.

This is the part of the patch which I think best addresses the concerns which raised this issue in the first place, that is adding special casing for BaseFieldDefinition everywhere.

Instead of seeing the special casing as a required part of base fields, it'd essentially become a helper for that one type of implementation.

Status: Needs review » Needs work

The last submitted patch, 22: 2346329-22.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

barraponto’s picture

Status: Needs work » Needs review
FileSize
10.79 KB

Re-rolling #22, fixes a couple of test failures by properly updating $fields array in language_entity_base_field_info_alter.
Also fixes BaseFieldDefinition::createFromFieldDefinition to only use methods available in FieldDefinitionInterface.

Status: Needs review » Needs work

The last submitted patch, 26: drupal-2346329-26.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

apaderno’s picture

Version: 8.9.x-dev » 9.0.x-dev
hash6’s picture

Assigned: Unassigned » hash6
xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev

I think this would be a minor-only change. Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!

kishor_kolekar’s picture

I've re-rolled patch for 9.1

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

apaderno’s picture

The patch failed for Drupal 9.2.x because an unused use statement in /core/modules/language/language.module, which hasn't be changed from the patch.

joachim’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Thanks for the analysis! Tagging as novice as it sounds like a simple thing to deal with.

Suresh Prabhu Parkala’s picture

Status: Needs work » Needs review
FileSize
11.18 KB

Re-roll against 9.2.x. Please review.

apaderno’s picture

Issue tags: +Needs reroll

@Suresh We need a patch for Drupal 9.3.x.

karishmaamin’s picture

Re-rolled patch for Drupal 9.3.x.

daffie’s picture

  1. +++ b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php
    @@ -94,6 +94,26 @@ public static function createFromFieldStorageDefinition(FieldStorageDefinitionIn
    +  public static function createFromFieldDefinition(FieldDefinitionInterface $definition) {
    

    Missing the parameter in the docblock.

  2. +++ b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php
    @@ -96,6 +96,29 @@ public static function createFromFieldStorageDefinition(FieldStorageDefinitionIn
    +  public static function createFromFieldDefinition(FieldDefinitionInterface $definition) {
    

    This new method is not used in core anywhere. At least we should add some testing for it.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Nikhil_110’s picture

Assigned: hash6 » Unassigned
FileSize
13.74 KB

Attached patch against Drupal 10.1.x

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

SpadXIII’s picture

FileSize
10.5 KB

rerolled against 9.5.x