Skip to content

Update hook_entity_insert() (and others) to use EntityInterface and make implementations in core consistant #2573

@YesCT

Description

@YesCT

Problem

There is an "and" in this title, so it might make sense to split into two issues, but...

grep -R --after=3 "Implements hook_entity_insert" *

or

ag -C3 "Implements hook_entity_insert" *

shows

core/modules/entity/tests/entity_crud_hook_test/entity_crud_hook_test.module
48-}
49-
50-/**
51: * Implements hook_entity_insert().
52- */
53-function entity_crud_hook_test_entity_insert($entity, $type) {
54-  $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type);

core/modules/filter/filter.module
1595-}
1596-
1597-/**
1598: * Implements hook_entity_insert().
1599- */
1600-function filter_entity_insert(EntityInterface $entity) {
1601-  $referenced_files_by_field = _filter_get_file_ids_by_field($entity);

core/modules/path/path.module
441-}
442-
443-/**
444: * Implements hook_entity_insert().
445- */
446-function path_entity_insert(Entity $entity) {
447-  $langcode = isset($entity->langcode) ? $entity->langcode : LANGUAGE_NONE;

And while working on a port of the mollom contrib module, I found a fail in one of the tests in the filter.module code. And I wondered why it had anything to do with filter. YesCT/mollom@814a250

#1088
#87

Proposed resolution

  • Update hook_entity_insert docs to take one argument of type EntityInterface
  • Update entity_crud_hook_test_entity_insert() to use that new API
  • Make a change record?

Remaining tasks

  • Find all similar hooks that should be updated.
    • hook_entity_insert()
    • hook_entity_update()
    • more?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions