You are here

protected function ScannerAdminForm::getEntityTypeFields in Search and Replace Scanner 8

Gets a list of entity fields as input options.

Parameters

array $available_entity_types: List of available entity types.

array $entity_types: The entity types, with their relevant bundles.

Return value

array An array containing the fields of the entity types.

1 call to ScannerAdminForm::getEntityTypeFields()
ScannerAdminForm::buildForm in src/Form/ScannerAdminForm.php
Form constructor.

File

src/Form/ScannerAdminForm.php, line 270

Class

ScannerAdminForm
Form for configuring the default scanner settings.

Namespace

Drupal\scanner\Form

Code

protected function getEntityTypeFields(array $available_entity_types, array $entity_types) {
  $options = [];

  // Iterate through each of the selected entity types and get their fields.
  foreach ($entity_types as $key => $value) {
    if (empty($value) || !isset($available_entity_types[$key])) {

      // Ignore the entity type if it's unticked
      // or the entity type no longer exists.
      continue;
    }
    list($entity_type, $bundle) = explode(':', $key);

    // Get the fields for the given entity type and bundle.
    $field_definitions = $this->entityFieldManager
      ->getFieldDefinitions($entity_type, $bundle);
    foreach ($field_definitions as $field_name => $field_definition) {
      $allowed_field_type = [
        // TODO:codebymikey:20200210 why no string_long?
        'string',
        'text_with_summary',
        'text',
        'text_long',
      ];

      // We are only interested in certain field types.
      if (in_array($field_definition
        ->getType(), $allowed_field_type, TRUE)) {

        // Skip fields starting with "parent_" (Paragraphs internal fields).
        if (strpos($field_name, 'parent_') === 0) {
          continue;
        }
        $name_with_type = "{$entity_type}:{$bundle}:{$field_name}";
        $options[$name_with_type] = $this
          ->t('@entity_bundle » @field_label <small><strong>(@field_name)</strong></small>', [
          '@entity_bundle' => $available_entity_types[$key],
          '@field_label' => $field_definition
            ->getLabel(),
          '@field_name' => $field_name,
        ]);
      }
    }
  }
  return $options;
}