class ResourceTypeRelationship
Same name in other branches
- 9 core/modules/jsonapi/src/ResourceType/ResourceTypeRelationship.php \Drupal\jsonapi\ResourceType\ResourceTypeRelationship
- 8.9.x core/modules/jsonapi/src/ResourceType/ResourceTypeRelationship.php \Drupal\jsonapi\ResourceType\ResourceTypeRelationship
- 10 core/modules/jsonapi/src/ResourceType/ResourceTypeRelationship.php \Drupal\jsonapi\ResourceType\ResourceTypeRelationship
Specialization of a ResourceTypeField to represent a resource relationship.
@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
Hierarchy
- class \Drupal\jsonapi\ResourceType\ResourceTypeField
- class \Drupal\jsonapi\ResourceType\ResourceTypeRelationship extends \Drupal\jsonapi\ResourceType\ResourceTypeField
Expanded class hierarchy of ResourceTypeRelationship
See also
https://www.drupal.org/project/drupal/issues/3032787
\Drupal\jsonapi\ResourceType\ResourceTypeRepository
4 files declare their use of ResourceTypeRelationship
- EntityReferenceFieldNormalizer.php in core/
modules/ jsonapi/ src/ Normalizer/ EntityReferenceFieldNormalizer.php - FieldResolver.php in core/
modules/ jsonapi/ src/ Context/ FieldResolver.php - ResourceIdentifierNormalizerTest.php in core/
modules/ jsonapi/ tests/ src/ Unit/ Normalizer/ ResourceIdentifierNormalizerTest.php - RoutesTest.php in core/
modules/ jsonapi/ tests/ src/ Unit/ Routing/ RoutesTest.php
File
-
core/
modules/ jsonapi/ src/ ResourceType/ ResourceTypeRelationship.php, line 16
Namespace
Drupal\jsonapi\ResourceTypeView source
class ResourceTypeRelationship extends ResourceTypeField {
/**
* The resource type to which this relationships can relate.
*
* @var \Drupal\jsonapi\ResourceType\ResourceType[]
*/
protected $relatableResourceTypes;
/**
* Establishes the relatable resource types of this field.
*
* @param array $resource_types
* The array of relatable resource types.
*
* @return static
* A new instance of the field with the given relatable resource types.
*/
public function withRelatableResourceTypes(array $resource_types) {
$relationship = new static($this->internalName, $this->publicName, $this->enabled, $this->hasOne);
$relationship->relatableResourceTypes = $resource_types;
return $relationship;
}
/**
* Gets the relatable resource types.
*
* @return \Drupal\jsonapi\ResourceType\ResourceType[]
* The resource type to which this relationships can relate.
*/
public function getRelatableResourceTypes() {
if (!isset($this->relatableResourceTypes)) {
throw new \LogicException("withRelatableResourceTypes() must be called before getting relatable resource types.");
}
return $this->relatableResourceTypes;
}
/**
* {@inheritdoc}
*/
public function withPublicName($public_name) {
$relationship = parent::withPublicName($public_name);
return isset($this->relatableResourceTypes) ? $relationship->withRelatableResourceTypes($this->relatableResourceTypes) : $relationship;
}
/**
* {@inheritdoc}
*/
public function disabled() {
$relationship = parent::disabled();
return isset($this->relatableResourceTypes) ? $relationship->withRelatableResourceTypes($this->relatableResourceTypes) : $relationship;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ResourceTypeField::$enabled | protected | property | Whether the field is disabled. | |
ResourceTypeField::$hasOne | protected | property | Whether the field can only have one value. | |
ResourceTypeField::$internalName | protected | property | The internal field name. | |
ResourceTypeField::$publicName | protected | property | The public field name. | |
ResourceTypeField::getInternalName | public | function | Gets the internal name of the field. | |
ResourceTypeField::getPublicName | public | function | Gets the public name of the field. | |
ResourceTypeField::hasMany | public | function | Whether the field can have many values. | |
ResourceTypeField::hasOne | public | function | Whether the field can only have one value. | |
ResourceTypeField::isFieldEnabled | public | function | Whether the field is enabled. | |
ResourceTypeField::__construct | public | function | ResourceTypeField constructor. | |
ResourceTypeRelationship::$relatableResourceTypes | protected | property | The resource type to which this relationships can relate. | |
ResourceTypeRelationship::disabled | public | function | Gets a new instance of the field that is disabled. | Overrides ResourceTypeField::disabled |
ResourceTypeRelationship::getRelatableResourceTypes | public | function | Gets the relatable resource types. | |
ResourceTypeRelationship::withPublicName | public | function | Establishes a new public name for the field. | Overrides ResourceTypeField::withPublicName |
ResourceTypeRelationship::withRelatableResourceTypes | public | function | Establishes the relatable resource types of this field. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.