You are here

protected function ResourceTypeRepository::getAllFieldNames in JSON:API 8.2

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

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.

2 calls to ResourceTypeRepository::getAllFieldNames()
CountableResourceTypeRepository::createResourceType in tests/modules/jsonapi_test_collection_count/src/ResourceType/CountableResourceTypeRepository.php
Creates a ResourceType value object for the given entity type + bundle.
ResourceTypeRepository::createResourceType in src/ResourceType/ResourceTypeRepository.php
Creates a ResourceType value object for the given entity type + bundle.

File

src/ResourceType/ResourceTypeRepository.php, line 265

Class

ResourceTypeRepository
Provides a repository of all JSON:API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

protected function getAllFieldNames(EntityTypeInterface $entity_type, $bundle) {
  if ($entity_type instanceof ContentEntityTypeInterface) {
    $field_definitions = $this->entityFieldManager
      ->getFieldDefinitions($entity_type
      ->id(), $bundle);
    return array_keys($field_definitions);
  }
  elseif ($entity_type instanceof ConfigEntityTypeInterface) {

    // @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',
      ];
    }
  }
  else {
    throw new \LogicException("Only content and config entity types are supported.");
  }
}