function ResourceTypeRepository::getAllFieldNames

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.

1 call to ResourceTypeRepository::getAllFieldNames()
ResourceTypeRepository::createResourceType in core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
Creates a ResourceType value object for the given entity type + bundle.

File

core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php, line 320

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.");
  }
}

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