You are here

public static function UtilsController::getEntityTextFields in Gutenberg 8.2

Get all the entity text fields.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: An entity instance.

Return value

array The entity text fields.

2 calls to UtilsController::getEntityTextFields()
gutenberg_form_node_form_alter in ./gutenberg.module
Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
MappingFieldsHelper::setFieldMappingValues in src/MappingFieldsHelper.php
Set the entity field values based on the mapping field settings.

File

src/Controller/UtilsController.php, line 65

Class

UtilsController
Utility controller.

Namespace

Drupal\gutenberg\Controller

Code

public static function getEntityTextFields(FieldableEntityInterface $entity) {

  /*
   * TODO Make the Gutenberg text field configurable rather than searching for
   *  the first formattable field.
   */
  $text_fields = [];

  // Iterate over all node fields and apply gutenberg text format
  // on first text field found.
  $field_names = self::getEntityFieldNames($entity);
  foreach ($field_names as $value) {
    $field_properties = array_keys($entity
      ->getFieldDefinition($value)
      ->getFieldStorageDefinition()
      ->getPropertyDefinitions());

    // It is long text field if it has format property.
    if (in_array('format', $field_properties)) {
      $text_fields[] = $value;
    }
  }
  return $text_fields;
}