AliasingResourceTypeRepository.php

Same filename in other branches
  1. 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_aliasing/src/ResourceType/AliasingResourceTypeRepository.php
  2. 8.9.x core/modules/jsonapi/tests/modules/jsonapi_test_field_aliasing/src/ResourceType/AliasingResourceTypeRepository.php
  3. 11.x core/modules/jsonapi/tests/modules/jsonapi_test_field_aliasing/src/ResourceType/AliasingResourceTypeRepository.php

Namespace

Drupal\jsonapi_test_field_aliasing\ResourceType

File

core/modules/jsonapi/tests/modules/jsonapi_test_field_aliasing/src/ResourceType/AliasingResourceTypeRepository.php

View source
<?php

namespace Drupal\jsonapi_test_field_aliasing\ResourceType;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\jsonapi\ResourceType\ResourceTypeRepository;

/**
 * Provides a repository of resource types with field names that can be aliased.
 */
class AliasingResourceTypeRepository extends ResourceTypeRepository {
    
    /**
     * {@inheritdoc}
     */
    protected function getFields(array $field_names, EntityTypeInterface $entity_type, $bundle) {
        $fields = parent::getFields($field_names, $entity_type, $bundle);
        foreach ($fields as $field_name => $field) {
            if (str_starts_with($field_name, 'field_test_alias_')) {
                $fields[$field_name] = $fields[$field_name]->withPublicName('field_test_alias');
            }
        }
        return $fields;
    }

}

Classes

Title Deprecated Summary
AliasingResourceTypeRepository Provides a repository of resource types with field names that can be aliased.

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