function EditorHooks::getFormattedTextFields

Determines the formatted text fields on an entity.

A field type is considered to provide formatted text if its class is a subclass of Drupal\text\Plugin\Field\FieldType\TextItemBase.

Parameters

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

Return value

array The names of the fields on this entity that support formatted text.

1 call to EditorHooks::getFormattedTextFields()
EditorHooks::getFileUuidsByField in core/modules/editor/src/Hook/EditorHooks.php
Finds all files referenced (data-entity-uuid) by formatted text fields.

File

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

Class

EditorHooks
Hook implementations for editor.

Namespace

Drupal\editor\Hook

Code

protected function getFormattedTextFields(FieldableEntityInterface $entity) : array {
  $field_definitions = $entity->getFieldDefinitions();
  if (empty($field_definitions)) {
    return [];
  }
  // Only return formatted text fields.
  // @todo improve as part of https://www.drupal.org/node/2732429
  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  return array_keys(array_filter($field_definitions, function (FieldDefinitionInterface $definition) use ($field_type_manager) {
    $type = $definition->getType();
    $plugin_class = $field_type_manager->getPluginClass($type);
    return is_subclass_of($plugin_class, TextItemBase::class);
  }));
}

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