Functions to be replaced

entity_reference_field_update_field
image_field_update_field
image_field_delete_field
image_field_update_instance
image_field_delete_instance
options_field_update_field
views_field_create_instance
views_field_update_instance
views_field_delete_instance
field_test_field_create_field
field_test_field_delete_instance

Functions to be removed

field_sql_storage_field_create_field

API changes

hook_field_read_field()
hook_field_create_field()
hook_field_update_field()
hook_field_delete_field()
hook_field_read_instance()
hook_field_create_instance()
hook_field_update_instance()
hook_field_delete_instance()

are replace by hook_ENTITY_TYPE_OP.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

FileSize
3.52 KB

Just a quick test on deleting hook_field_delete_field as there's only one implementation.

Also note to self, need to look for hook_field_read_field and hook_field_read_instance implementations.

swentel’s picture

Status: Active » Needs review
swentel’s picture

FileSize
26.67 KB

This should have them all - except for read

Status: Needs review » Needs work

The last submitted patch, 2013939-3.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
26.63 KB

Fixes the image tests.

amateescu’s picture

+++ b/core/modules/entity_reference/entity_reference.module
@@ -192,33 +192,35 @@ function entity_reference_field_settings_form($field, $instance, $has_data) {
+function entity_reference_entity_update_update(EntityInterface $entity) {

This doesn't look right :)

Status: Needs review » Needs work

The last submitted patch, 2013939-5.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
2.08 KB
26.61 KB

@amateescu - haha. Note, in case someone starts screaming for a test, do that in a follow up!

In the meantime, fix the rest of the tests.

swentel’s picture

FileSize
1.77 KB
40.17 KB

And last hooks: goodbye hook_field_read_field() and hook_field_read_instance()

swentel’s picture

FileSize
27.96 KB

That was so totally wrong

yched’s picture

Status: Needs review » Needs work

Thanks for this !

+++ b/core/modules/entity_reference/entity_reference.moduleundefined
@@ -192,33 +192,35 @@ function entity_reference_field_settings_form($field, $instance, $has_data) {
-function entity_reference_field_update_field($field, $prior_field, $has_data) {
-  if ($field['type'] != 'entity_reference') {
-    // Not an entity reference field.
-    return;
-  }
+function entity_reference_entity_update(EntityInterface $entity) {

For performance, I guess it's recommended to rather implement hook_[ENTITY_TYPE]_[OP]() ?

The "generic" hook_entity_[OP]() are there for the cases where you want to react for all config entities, or all fieldable entities...

(also applies to the other hook migrations in the patch ?)

+++ b/core/modules/entity_reference/entity_reference.moduleundefined
@@ -192,33 +192,35 @@ function entity_reference_field_settings_form($field, $instance, $has_data) {
+  if ($entity->entityType() == 'field_entity' && $entity->type == 'entity_reference') {
+    if ($entity['type'] != 'entity_reference') {

Something looks weird here. $entity->type is checked twice with BC/array and object syntax ?

Since this code is de facto new code, I'd say it should not continue using the BC array syntax. $entity['foo'] definitely looks weird :-)
(same for the new image_entity_[op]() implementations)

+++ b/core/modules/entity_reference/entity_reference.moduleundefined
@@ -192,33 +192,35 @@ function entity_reference_field_settings_form($field, $instance, $has_data) {
-  $field_name = $field['field_name'];
+    $field_name = $$entity['field_name'];

double $$
(and switch to ->id() ?)

+++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.phpundefined
@@ -372,6 +384,7 @@ public function save() {
       $has_data = field_has_data($this);
+      $this->hasData = $has_data;

That's a property that only exists at a specific point in the object lifecycle (during save() if updating an existing field entity), but is documented as always being present. We should move field_has_data() to a method on the Field entity IMO.

+++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.phpundefined
@@ -347,13 +361,11 @@ public function save() {
+      $this->originalField = $original;

Not great either, for the same reasons. Less sure about how we can make that better, though.

This looks like a more general issue with hook_entity_update().
I opened #2017809: how do hook_entity_update() implementations access the "previous" state of the entity ? for this.

No better suggestion for now, let's leave it that way here, I guess...
(same for FieldInstance::$originalInstance - maybe at least name both properties just "$original" ?)

Nitpick: I think core tends to avoid starting function bodies with an empty line.

swentel’s picture

hook_[ENTITY_TYPE]_[OP]()

Been looking for that, but this doesn't seem to be supported, unless I'm really stupid ...

Will look at the other ones this evening.

yched’s picture

hook_[ENTITY_TYPE]_[OP]() :
see ConfigStorageController::invokeHook()

swentel’s picture

Oh, crap shoot me, I just saw

    $this->invokeHook('create', $entity);

and was like, damn, that's sad. Note to self: click the actual method, djeezes.

yched’s picture

Nope, /me won't shoot @swentel

swentel’s picture

Status: Needs work » Needs review
FileSize
18.58 KB
26.73 KB

This is pretty badass now. Not sure if the interdiff is useful as it's pretty big :)

- Changed all hooks - talked to timplunkett how the docblock should be for it.
- removed BC where possible
- The 'original' properties are the same
- I left hasData as is for now as it's also used in hook_update_forbid and I didn't want to start touching those hooks as well. I'm fine with a follow up if you're ok with that
- One line nitpicks :)

Let's see if I didn't forget anything.

Status: Needs review » Needs work
Issue tags: -Field API

The last submitted patch, 2013939-16.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
Issue tags: +Field API

#16: 2013939-16.patch queued for re-testing.

yched’s picture

OK, let's go with a followup for hasData.

IMO we could write:

function entity_reference_field_entity_update(EntityInterface $field) {

which would make code in the func body much easier to understand.

Maybe even :

function entity_reference_field_entity_update(FieldInterface $field) {

but I'm less sure about that.

swentel’s picture

Good point, I'll see how it behaves with FieldInterface or FieldInstanceInterface

swentel’s picture

swentel’s picture

FileSize
10.54 KB
27.35 KB

Seems to work fine

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks good :-)
RTBC if green.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2013939-22.patch, failed testing.

yched’s picture

"Argument 1 passed to field_test_field_instance_delete() must be an instance of FieldInstanceInterface, instance of Drupal\field\Plugin\Core\Entity\FieldInstance given"

This looks like a missing "use" statement for FieldInstanceInterface in field_test.something :-)

swentel’s picture

Status: Needs work » Needs review
FileSize
1.67 KB
27.5 KB

Yes indeed :) Found two minor docblock mistakes too while fixing it.

yched’s picture

Status: Needs review » Reviewed & tested by the community

... if green

yched’s picture

amateescu’s picture

FileSize
26.1 KB

Rerolled.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2013939-29.patch, failed testing.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.25 KB
26.12 KB
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll

curl https://drupal.org/files/2013939-31.patch | git a
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 26745  100 26745    0     0  11895      0  0:00:02  0:00:02 --:--:-- 16053
error: patch failed: core/modules/entity_reference/entity_reference.module:169
error: core/modules/entity_reference/entity_reference.module: patch does not apply
swentel’s picture

Issue tags: -Needs reroll

There's more todo than a reroll because of #2018731: Move field_has_data() to Field::hasData()

pcambra’s picture

Status: Needs work » Needs review
FileSize
26.01 KB

Actually entity_reference_field_update_field is the conflicting function and there's no "has data" check there, so here's a re-roll #31

swentel’s picture

Status: Needs review » Needs work
+++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.phpundefined
@@ -196,6 +196,13 @@ class Field extends ConfigEntityBase implements FieldInterface {
   /**
+   * Whether the field has data. This property is only available on update.
+   *
+   * @var boolean
+   */
+  public $hasData = FALSE;

This should go now, people need to use the static method if they want to use it.

pcambra’s picture

Status: Needs work » Needs review
FileSize
633 bytes
25.7 KB

Removing has data reference mentioned in #35

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Sweet!

Status: Reviewed & tested by the community » Needs work
Issue tags: -Field API

The last submitted patch, 2013939-36.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
Issue tags: +Field API

#36: 2013939-36.patch queued for re-testing.

swentel’s picture

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

Issue tags: -Field API

#36: 2013939-36.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2013939-36.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
Issue tags: +Field API

#36: 2013939-36.patch queued for re-testing.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC. Sorry for the noise. Just wanted to make sure it still passed after other Field API commits in the last 12 hours.

alexpott’s picture

Title: Remove hook_field_CRUD_() in favor of hook_entity_TYPE_CRUD() calls » Change notice: Remove hook_field_CRUD_() in favor of hook_entity_TYPE_CRUD() calls
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed 5ff3e98 and pushed to 8.x. Thanks!

yched’s picture

Title: Change notice: Remove hook_field_CRUD_() in favor of hook_entity_TYPE_CRUD() calls » Remove hook_field_CRUD_() in favor of hook_entity_TYPE_CRUD() calls
Priority: Critical » Major
Status: Active » Fixed
Issue tags: -Needs change record

Change notification added at https://drupal.org/node/2054619

yched’s picture

Title: Remove hook_field_CRUD_() in favor of hook_entity_TYPE_CRUD() calls » Remove hook_field_[CRUD]_() in favor of hook_ENTITY_TYPE_[CRUD]() calls

More accurate title for posterity

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.