You are here

class ConfigEntityNormalizer in JSON:API 8

Converts the Drupal config entity object to a JSON API array structure.

@internal

Hierarchy

Expanded class hierarchy of ConfigEntityNormalizer

1 file declares its use of ConfigEntityNormalizer
ConfigEntityNormalizerTest.php in tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php
1 string reference to 'ConfigEntityNormalizer'
jsonapi.services.yml in ./jsonapi.services.yml
jsonapi.services.yml
1 service uses ConfigEntityNormalizer
serializer.normalizer.config_entity.jsonapi in ./jsonapi.services.yml
Drupal\jsonapi\Normalizer\ConfigEntityNormalizer

File

src/Normalizer/ConfigEntityNormalizer.php, line 16

Namespace

Drupal\jsonapi\Normalizer
View source
class ConfigEntityNormalizer extends EntityNormalizer {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string
   */
  protected $supportedInterfaceOrClass = ConfigEntityInterface::class;

  /**
   * {@inheritdoc}
   */
  protected function getFields($entity, $bundle, ResourceType $resource_type) {
    $enabled_public_fields = [];
    $fields = static::getDataWithoutInternals($entity
      ->toArray());

    // Filter the array based on the field names.
    $enabled_field_names = array_filter(array_keys($fields), [
      $resource_type,
      'isFieldEnabled',
    ]);

    // Return a sub-array of $output containing the keys in $enabled_fields.
    $input = array_intersect_key($fields, array_flip($enabled_field_names));

    /* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    foreach ($input as $field_name => $field_value) {
      $public_field_name = $resource_type
        ->getPublicName($field_name);
      $enabled_public_fields[$public_field_name] = $field_value;
    }
    return $enabled_public_fields;
  }

  /**
   * {@inheritdoc}
   */
  protected function serializeField($field, array $context, $format) {
    return new FieldNormalizerValue(AccessResult::allowed(), [
      new ConfigFieldItemNormalizerValue($field),
    ], 1, 'attributes');
  }

  /**
   * Gets the given data without the internal implementation details.
   *
   * @param array $data
   *   The data that is either currently or about to be stored in configuration.
   *
   * @return array
   *   The same data, but without internals. Currently, that is only the '_core'
   *   key, which is reserved by Drupal core to handle complex edge cases
   *   correctly. Data in the '_core' key is irrelevant to clients reading
   *   configuration, and is not allowed to be set by clients writing
   *   configuration: it is for Drupal core only, and managed by Drupal core.
   *
   * @see https://www.drupal.org/node/2653358
   * @see \Drupal\serialization\Normalizer\ConfigEntityNormalizer::getDataWithoutInternals
   */
  protected static function getDataWithoutInternals(array $data) {
    return array_diff_key($data, [
      '_core' => TRUE,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
ConfigEntityNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides EntityNormalizer::$supportedInterfaceOrClass
ConfigEntityNormalizer::getDataWithoutInternals protected static function Gets the given data without the internal implementation details.
ConfigEntityNormalizer::getFields protected function Gets the field names for the given entity. Overrides EntityNormalizer::getFields
ConfigEntityNormalizer::serializeField protected function Serializes a given field. Overrides EntityNormalizer::serializeField
EntityNormalizer::$entityTypeManager protected property The entity type manager.
EntityNormalizer::$formats protected property The formats that the Normalizer can handle. Overrides NormalizerBase::$formats
EntityNormalizer::$linkManager protected property The link manager.
EntityNormalizer::$resourceTypeRepository protected property The JSON API resource type repository.
EntityNormalizer::denormalize public function Denormalizes data back into an object of the given class.
EntityNormalizer::getFieldItemInstance protected function Gets a field item instance for use with SerializedColumnNormalizerTrait.
EntityNormalizer::getFieldNames protected function Gets the field names for the given entity.
EntityNormalizer::normalize public function Normalizes an object into a set of arrays/scalars.
EntityNormalizer::prepareInput protected function Prepares the input data to create the entity.
EntityNormalizer::__construct public function Constructs an EntityNormalizer object.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase::supportsDenormalization
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase::supportsNormalization
SerializedColumnNormalizerTrait::checkForSerializedStrings protected function Checks if there is a serialized string for a column.
SerializedColumnNormalizerTrait::dataHasStringForSerializeColumn protected function Checks if the data contains string value for serialize column.
SerializedColumnNormalizerTrait::getCustomSerializedPropertyNames protected function Gets the names of all properties the plugin treats as serialized data.
SerializedColumnNormalizerTrait::getSerializedPropertyNames protected function Gets the names of all serialized properties.