function ViewsEntityTestHooks::entityLoad

Implements hook_entity_load().

Attributes

#[Hook('entity_load')]

See also

\Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testSimpleExecute()

File

core/modules/views/tests/modules/views_entity_test/src/Hook/ViewsEntityTestHooks.php, line 63

Class

ViewsEntityTestHooks
Hook implementations for views_entity_test.

Namespace

Drupal\views_entity_test\Hook

Code

public function entityLoad(array $entities, $entity_type_id) : void {
  if ($entity_type_id === 'entity_test') {
    // Cast the value of an entity field to be something else than a string so
    // we can check that
    // \Drupal\views\Tests\ViewResultAssertionTrait::assertIdenticalResultsetHelper()
    // takes care of converting all field values to strings.
    foreach ($entities as $entity) {
      $entity->user_id->target_id = (int) $entity->user_id->target_id;
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.