Chris@18: uuid(), Chris@18: $resource_type->isVersionable() && $entity instanceof RevisionableInterface ? $entity->getRevisionId() : NULL, Chris@18: static::extractFieldsFromEntity($resource_type, $entity), Chris@18: static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])) Chris@18: ); Chris@18: $resource_object->setEntity($entity); Chris@18: return $resource_object; Chris@18: } Chris@18: Chris@18: /** Chris@18: * Gets the decorated entity. Chris@18: * Chris@18: * @return \Drupal\Core\Entity\EntityInterface Chris@18: * The label for which to only normalize its label. Chris@18: */ Chris@18: public function getEntity() { Chris@18: return $this->entity; Chris@18: } Chris@18: Chris@18: /** Chris@18: * Sets the underlying entity. Chris@18: * Chris@18: * @param \Drupal\Core\Entity\EntityInterface $entity Chris@18: * An entity. Chris@18: */ Chris@18: protected function setEntity(EntityInterface $entity) { Chris@18: $this->entity = $entity; Chris@18: } Chris@18: Chris@18: /** Chris@18: * {@inheritdoc} Chris@18: */ Chris@18: protected static function extractFieldsFromEntity(ResourceType $resource_type, EntityInterface $entity) { Chris@18: $fields = parent::extractFieldsFromEntity($resource_type, $entity); Chris@18: $public_label_field_name = $resource_type->getPublicName(static::getLabelFieldName($entity)); Chris@18: return array_intersect_key($fields, [$public_label_field_name => TRUE]); Chris@18: } Chris@18: Chris@18: }