You are here

public function Drupal8::hookEntityPresave in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::hookEntityPresave()
  2. 7.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::hookEntityPresave()

React to an entity just before it is saved.

Overrides Framework::hookEntityPresave

File

api/src/Framework/Drupal8.php, line 23

Class

Drupal8
Drupal 8-specific code.

Namespace

Drupal\realistic_dummy_content_api\Framework

Code

public function hookEntityPresave($entity) {
  try {
    $type = $this
      ->getEntityType($entity);
    if (realistic_dummy_content_api_is_dummy($entity, $type)) {
      $candidate = $entity;
      realistic_dummy_content_api_improve_dummy_content($candidate, $type);
      realistic_dummy_content_api_validate($candidate, $type);
      $entity = $candidate;
    }
  } catch (\Throwable $e) {

    // @phpstan-ignore-next-line
    \Drupal::messenger()
      ->addMessage($this
      ->t('realistic_dummy_content_api failed to modify dummy objects: message: @m', [
      '@m' => $e
        ->getMessage(),
    ]), 'error', FALSE);
  }
}