You are here

public function EntityHook::onEntityInsert in Editor Notes 8

Save Editor Note on entity insert.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Entity object.

See also

editor_note_entity_insert

File

src/Hook/EntityHook.php, line 66

Class

EntityHook
Be aware of some entity hooks to perform actions on editor note.

Namespace

Drupal\editor_note\Hook

Code

public function onEntityInsert(EntityInterface $entity) {
  if (!$entity instanceof FieldableEntityInterface) {
    return;
  }
  $field_definitions = $entity
    ->getFieldDefinitions();
  foreach ($field_definitions as $field_name => $field_definition) {
    if ($field_definition
      ->getType() === 'editor_note_item') {
      $note_value = $entity
        ->get($field_name)->value;
      if (empty($note_value)) {
        return;
      }

      // Create Editor Note entity.
      $this->editorNoteHelper
        ->createNote($entity, $field_name, $note_value);
    }
  }
}