public function EditorNoteHelperService::createNote in Editor Notes 8
Create 'Editor Node' entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $host_entity: Host entity to attach editor note.
string $field_machine_name: Host entity editor note field machine name.
string $note: Editor note.
string $format: Text format.
File
- src/
EditorNoteHelperService.php, line 102
Class
- EditorNoteHelperService
- Class EditorNoteHelperService.
Namespace
Drupal\editor_noteCode
public function createNote(ContentEntityInterface $host_entity, $field_machine_name, $note, $format = 'plain_text') {
$storage = $this->entityTypeManager
->getStorage('editor_note');
$entityType = $host_entity
->getEntityType();
$data = [
'entity_id' => $host_entity
->id(),
'entity_type' => $entityType
->id(),
'revision_id' => $host_entity
->getRevisionId() ?? 0,
'note' => [
'value' => $note,
'format' => $format,
],
'bundle' => $host_entity
->bundle(),
'field_machine_name' => $field_machine_name,
];
$note = $storage
->create($data);
$note
->save();
}