function ResourceTestBase::decorateResourceIdentifierWithDrupalInternalTargetId
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::decorateResourceIdentifierWithDrupalInternalTargetId()
- 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::decorateResourceIdentifierWithDrupalInternalTargetId()
Adds drupal_internal__target_id to the meta of a resource identifier.
Parameters
\Drupal\Core\Field\FieldItemInterface|\Drupal\Core\Field\FieldItemListInterface $field: The field containing the entity that is described by the resource_identifier.
array $resource_identifier: A resource identifier for an entity.
Return value
array A resource identifier for an entity with drupal_internal__target_id set if appropriate.
1 call to ResourceTestBase::decorateResourceIdentifierWithDrupalInternalTargetId()
- ResourceTestBase::getExpectedGetRelationshipDocumentData in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Gets the expected document data for the given relationship.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 1830
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected static function decorateResourceIdentifierWithDrupalInternalTargetId($field, array $resource_identifier) : array {
$property_definitions = $field->getFieldDefinition()
->getFieldStorageDefinition()
->getPropertyDefinitions();
if (!isset($property_definitions['target_id'])) {
return $resource_identifier;
}
$is_data_reference_definition = $property_definitions['target_id'] instanceof DataReferenceTargetDefinition;
if ($is_data_reference_definition) {
// Numeric target IDs usually reference content entities, which use an
// auto-incrementing integer ID. Non-numeric target IDs usually reference
// config entities, which use a machine-name as an ID.
$resource_identifier['meta']['drupal_internal__target_id'] = is_numeric($field->target_id) ? (int) $field->target_id : $field->target_id;
}
return $resource_identifier;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.