You are here

protected function JsonapiResourceConfigForm::getAllFieldNames in JSON:API Extras 8.3

Gets all field names for a given entity type and bundle.

@todo This is a copy of ResourceTypeRepository::getAllFieldNames. We can't reuse that code because it's protected.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type for which to get all field names.

string $bundle: The bundle for which to get all field names.

Return value

string[] All field names.

1 call to JsonapiResourceConfigForm::getAllFieldNames()
JsonapiResourceConfigForm::buildOverridesForm in src/Form/JsonapiResourceConfigForm.php
Builds the part of the form that contains the overrides.

File

src/Form/JsonapiResourceConfigForm.php, line 522

Class

JsonapiResourceConfigForm
Base form for jsonapi_resource_config.

Namespace

Drupal\jsonapi_extras\Form

Code

protected function getAllFieldNames(EntityTypeInterface $entity_type, $bundle) {
  if (is_a($entity_type
    ->getClass(), FieldableEntityInterface::class, TRUE)) {
    $field_definitions = $this->fieldManager
      ->getFieldDefinitions($entity_type
      ->id(), $bundle);
    return array_keys($field_definitions);
  }
  elseif (is_a($entity_type
    ->getClass(), ConfigEntityInterface::class, TRUE)) {

    // @todo Uncomment the first line, remove everything else once https://www.drupal.org/project/drupal/issues/2483407 lands.
    // return array_keys($entity_type->getPropertiesToExport());
    $export_properties = $entity_type
      ->getPropertiesToExport();
    if ($export_properties !== NULL) {
      return array_keys($export_properties);
    }
    else {
      return [
        'id',
        'type',
        'uuid',
        '_core',
      ];
    }
  }
  return [];
}