getNonInternalProperties example


  public function normalize($field_item$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    assert($field_item instanceof FieldItemInterface);
    /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
    $values = [];
    $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY] = new CacheableMetadata();
    if (!empty($field_item->getProperties(TRUE))) {
      // We normalize each individual value, so each can do their own casting,       // if needed.       $field_properties = TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item);
      foreach ($field_properties as $property_name => $property) {
        $values[$property_name] = $this->serializer->normalize($property$format$context);
      }
      // Flatten if there is only a single property to normalize.       $flatten = count($field_properties) === 1 && $field_item::mainPropertyName() !== NULL;
      $values = static::rasterizeValueRecursive($flatten ? reset($values) : $values);
    }
    else {
      $values = $field_item->getValue();
    }
    $normalization = new CacheableNormalization(
      

  public function normalize($object$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    $attributes = [];
    // $object will not always match $supportedInterfaceOrClass.     // @see \Drupal\serialization\Normalizer\EntityNormalizer     // Other normalizers that extend this class may only provide $object that     // implements \Traversable.     if ($object instanceof ComplexDataInterface) {
      // If there are no properties to normalize, just normalize the value.       $object = !empty($object->getProperties(TRUE))
        ? TypedDataInternalPropertiesHelper::getNonInternalProperties($object)
        : $object->getValue();
    }
    /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
    foreach ($object as $name => $property) {
      $attributes[$name] = $this->serializer->normalize($property$format$context);
    }
    return $attributes;
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  public function normalize($entity$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    $context += [
      'account' => NULL,
    ];

    $attributes = [];
    /** @var \Drupal\Core\Entity\Entity $entity */
    foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData()) as $name => $field_items) {
      if ($field_items->access('view', $context['account'])) {
        $attributes[$name] = $this->serializer->normalize($field_items$format$context);
      }
    }

    return $attributes;
  }

  /** * {@inheritdoc} */
  

  protected static function extractContentEntityFields(ResourceType $resource_type, ContentEntityInterface $entity) {
    $output = [];
    $fields = TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData());
    // Filter the array based on the field names.     $enabled_field_names = array_filter(
      array_keys($fields),
      [$resource_type, 'isFieldEnabled']
    );

    // Special handling for user entities that allows a JSON:API user agent to     // access the display name of a user. For example, this is useful when     // displaying the name of a node's author.     // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.     $entity_type = $entity->getEntityType();
    
$property_name = static::getDataReferencePropertyName($item);
    $target = $item->get($property_name)->getValue();
    if ($target === NULL) {
      return static::getVirtualOrMissingResourceIdentifier($item);
    }
    assert($target instanceof EntityInterface);
    /** @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository */
    $resource_type_repository = \Drupal::service('jsonapi.resource_type.repository');
    $resource_type = $resource_type_repository->get($target->getEntityTypeId()$target->bundle());
    // Remove unwanted properties from the meta value, usually 'entity'     // and 'target_id'.     $properties = TypedDataInternalPropertiesHelper::getNonInternalProperties($item);
    $main_property_name = $item->getDataDefinition()->getMainPropertyName();
    $meta = array_diff_key($propertiesarray_flip([$property_name$main_property_name]));
    if (!is_null($arity)) {
      $meta[static::ARITY_KEY] = $arity;
    }
    $meta["drupal_internal__$main_property_name"] = $properties[$main_property_name];
    return new static($resource_type$target->uuid()$meta);
  }

  /** * Creates an array of ResourceIdentifier objects. * * @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items * The entity reference field items from which to create the relationship * array. * * @return self[] * An array of new ResourceIdentifier objects with appropriate arity values. */
if ($access_result->isAllowed()) {
        $cacheability->addCacheableDependency($entity);
        if ($entity instanceof FieldableEntityInterface) {
          foreach ($entity as $field_name => $field_item_list) {
            /** @var \Drupal\Core\Field\FieldItemListInterface $field_item_list */
            if (is_null($sparse_fieldset) || in_array($field_name$sparse_fieldset)) {
              $field_access = static::entityFieldAccess($entity$field_name, 'view', $account);
              $cacheability->addCacheableDependency($field_access);
              if ($field_access->isAllowed()) {
                foreach ($field_item_list as $field_item) {
                  /** @var \Drupal\Core\Field\FieldItemInterface $field_item */
                  foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item) as $property) {
                    $cacheability->addCacheableDependency(CacheableMetadata::createFromObject($property));
                  }
                }
              }
            }
          }
        }
      }
      return $cacheability;
    }new CacheableMetadata());
    $entity_type = reset($collection)->getEntityType();
    
Home | Imprint | This part of the site doesn't use cookies.