function EditorHooks::getFileUuidsByField

Finds all files referenced (data-entity-uuid) by formatted text fields.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: An entity whose fields to analyze.

Return value

array An array of file entity UUIDs.

4 calls to EditorHooks::getFileUuidsByField()
EditorHooks::entityDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_delete().
EditorHooks::entityInsert in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_insert().
EditorHooks::entityRevisionDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_revision_delete().
EditorHooks::entityUpdate in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_update().

File

core/modules/editor/src/Hook/EditorHooks.php, line 422

Class

EditorHooks
Hook implementations for editor.

Namespace

Drupal\editor\Hook

Code

protected function getFileUuidsByField(FieldableEntityInterface $entity) : array {
  $uuids = [];
  $formatted_text_fields = $this->getFormattedTextFields($entity);
  foreach ($formatted_text_fields as $formatted_text_field) {
    $text = '';
    $field_items = $entity->get($formatted_text_field);
    foreach ($field_items as $field_item) {
      $text .= $field_item->value;
      if ($field_item->getFieldDefinition()
        ->getType() == 'text_with_summary') {
        $text .= $field_item->summary;
      }
    }
    $uuids[$formatted_text_field] = $this->parseFileUuids($text);
  }
  return $uuids;
}

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