class CollectRelationshipMetaEvent

Event for collecting the relationship metadata of a JSON:API resource object.

Subscribers of this event that call ::setMetaValue() must set the appropriate cache tags and contexts. These should be based on the data that is used to set the meta. These will then bubble up to the normalization.

Hierarchy

Expanded class hierarchy of CollectRelationshipMetaEvent

Related topics

3 files declare their use of CollectRelationshipMetaEvent
EntityResource.php in core/modules/jsonapi/src/Controller/EntityResource.php
MetaEventSubscriber.php in core/modules/jsonapi/tests/modules/jsonapi_test_meta_events/src/EventSubscriber/MetaEventSubscriber.php
ResourceObjectNormalizer.php in core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php

File

core/modules/jsonapi/src/Events/CollectRelationshipMetaEvent.php, line 22

Namespace

Drupal\jsonapi\Events
View source
final class CollectRelationshipMetaEvent extends Event implements RefinableCacheableDependencyInterface {
    use RefinableCacheableDependencyTrait;
    
    /**
     * The metadata.
     *
     * @var array
     */
    private array $meta = [];
    
    /**
     * Constructs a new CollectRelationshipMetaEvent object.
     *
     * @param \Drupal\jsonapi\JsonApiResource\ResourceObject $resourceObject
     *   The resource object.
     * @param string $relationshipFieldName
     *   The relationship field name.
     */
    public function __construct(ResourceObject $resourceObject, string $relationshipFieldName) {
    }
    
    /**
     * Gets the resource object.
     *
     * @return \Drupal\jsonapi\JsonApiResource\ResourceObject
     *   The resource object.
     */
    public function getResourceObject() : ResourceObject {
        return $this->resourceObject;
    }
    
    /**
     * Gets the relationship field.
     *
     * @return string
     *   The relationship field name.
     */
    public function getRelationshipFieldName() : string {
        return $this->relationshipFieldName;
    }
    
    /**
     * Gets the meta values.
     *
     * @return array
     *   The meta.
     */
    public function getMeta() : array {
        return $this->meta;
    }
    
    /**
     * Sets a meta value.
     *
     * @param array|string $property
     *   The key or array of keys.
     * @param mixed $value
     *   The value.
     *
     * @return $this
     */
    public function setMetaValue(array|string $property, mixed $value) : self {
        NestedArray::setValue($this->meta, (array) $property, $value, TRUE);
        return $this;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 4
CacheableDependencyTrait::getCacheMaxAge public function 4
CacheableDependencyTrait::getCacheTags public function 4
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
CollectRelationshipMetaEvent::$meta private property The metadata.
CollectRelationshipMetaEvent::getMeta public function Gets the meta values.
CollectRelationshipMetaEvent::getRelationshipFieldName public function Gets the relationship field.
CollectRelationshipMetaEvent::getResourceObject public function Gets the resource object.
CollectRelationshipMetaEvent::setMetaValue public function Sets a meta value.
CollectRelationshipMetaEvent::__construct public function Constructs a new CollectRelationshipMetaEvent object.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function

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