Motivation

Field items and field item lists implement the typed data interface, what leads to same confusing method names.

Proposed resolution

Let's rename them:

Taken from #2002138-51: Use an adapter for supporting typed data on ContentEntities and updated:

  • getDefinition() -> getDataDefinition()
  • getName() + getParent() -> getDataContext()
  • setContext() - either rename to e.g. setDataContext() or remove in #2268009: Make typed data object instantiation more flexible
  • getPropertyPath() -> replace with a method on the manager working based on getDataContext() (it's hardly used anyway)
  • getRoot() -> replace as getPropertyPath() with a method on the manager, (getEntity() can stay)

Remaining tasks

Do it.

User interface changes

-

API changes

- The method names change. Those methods are on entities, field items, field item lists and field item properties right now.

Comments

fago’s picture

yched’s picture

- re: getDataDefinition(), getDataContext(), setDataContext()...
I've lost track a bit on the current status of #2002138: Use an adapter for supporting typed data on ContentEntities and whether we still intend to have FieldItem[List] implements TypedDatainterface directly.

If we do, then I'm not sure whether, within the context of the business logic of FieldItem[List], "Data" is specific enough to clearly relate the methods to the TypedData API. Going with a full "getTypedDataDefinition()" might be clearer ?

- re: getName()
I think there is some existing code that uses FieldItemList::getName() to get "the field name" - with the confusing drawback that doing the same on a FieldItem gives you the delta instead of the field name... So yeah, either removing the mehtod or making it more clearly related to TypedData API rather than Field API would be good.

If we remove it, should we introduce getFieldName() on FieldItem / FieldItemList ? (merely as a handy shortcut to $this->getFieldDefinition()->getName() ?)

- Less sure about moving getPropertyPath() & getRoot() out of the the TypedData object and into the TDManager. I mean, those are rarely used, and I can see why we might want to move them out of the way from domain objects like FieldItem & stuff, but those are information held by the TypedData objects, it seems weird/artificial to have the getters for those not on the objects themeselves ?

But maybe it's just I'm not clearly seeing what it would look like ?

fago’s picture

If we do, then I'm not sure whether, within the context of the business logic of FieldItem[List], "Data" is specific enough to clearly relate the methods to the TypedData API. Going with a full "getTypedDataDefinition()" might be clearer ?

True, but it's already getDataDefinition() now in HEAD and I must say getTypedDataDefinition() is a bit weird on a TypedDataInterface :/

- Less sure about moving getPropertyPath() & getRoot() out of the the TypedData object and into the TDManager. I mean, those are rarely used, and I can see why we might want to move them out of the way from domain objects like FieldItem & stuff, but those are information held by the TypedData objects, it seems weird/artificial to have the getters for those not on the objects themeselves ?

Those are helper methods which generate the path based upon getParent() & getName(), so they could live outside the object and operate on that. Imo it's fine as further helpers like resolving a data selector "entity.field.0.value" shouldn't go into the objects either.

I've lost track a bit on the current status of #2002138: Use adapters for supporting typed data and whether we still intend to have FieldItem[List] implements TypedDatainterface directly.

The plan would be to keep them using TypedDatainterface, so this issue would help to make sure the methods on them do not confuse people. At the current state converting them to an adapter seems to be a huge undertaking given all the property creation, computed properties, change handling etc. relies on typed data functionality - at least if we do not duplicate all that code.

If we remove it, should we introduce getFieldName() on FieldItem / FieldItemList ? (merely as a handy shortcut to $this->getFieldDefinition()->getName() ?)

Seems useful, yes. I'm wondering whether it would make sense to add it right now; it's just a little bit weird when both getName() and getFieldName() are there and do the same.

yched’s picture

I must say getTypedDataDefinition() is a bit weird on a TypedDataInterface :/

Not really, if TypeDataInterface is kind enough to acknowledge itself as a "secondary interface", used on objects which already have their own domain interface which is what most consumers consider as the primary identity of the object :-)

path / root --> TDManager: fair enough, this is about recursing on parent / path properties of a $data, why not.

yched’s picture

Then again, I'd see no problem with TDI::getTypedDataRoot() & getTypedDataPath() :-)

fago’s picture

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

I think that ship has sailed for d8, or could it be 8.1.x maybe? No idea what's going to be allowed for 8.1.x but we'll see.

yched’s picture

Agreed, seems a bit late now...

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now 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.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.

fago’s picture

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

This is clearly a d9 topic.

catch’s picture

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

9.x may end up only dropping backwards compatibility from Drupal 8. Therefore we should explore doing this in a backwards compatible way in 8.x before we give up completely.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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.

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.

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.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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.

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.

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.