You are here

protected function JsonapiHelper::setChangedTime in Entity Share 8.2

Change the entity "changed" time.

Because it could have been altered with relationship saved by example.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to update.

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The resource type related to the entity.

array $entity_data: The JSON data.

1 call to JsonapiHelper::setChangedTime()
JsonapiHelper::importEntityListData in modules/entity_share_client/src/Service/JsonapiHelper.php
Use data from the JSON:API to import content.

File

modules/entity_share_client/src/Service/JsonapiHelper.php, line 921

Class

JsonapiHelper
Class JsonapiHelper.

Namespace

Drupal\entity_share_client\Service

Code

protected function setChangedTime(ContentEntityInterface $entity, ResourceType $resource_type, array $entity_data) {
  $changed_public_name = FALSE;
  if ($resource_type
    ->hasField('changed')) {
    $changed_public_name = $resource_type
      ->getPublicName('changed');
  }
  if ($changed_public_name && !empty($entity_data['attributes'][$changed_public_name]) && method_exists($entity, 'setChangedTime')) {

    // If the website is using backward compatible timestamps output.
    // @see https://www.drupal.org/node/2859657.
    if (is_numeric($entity_data['attributes'][$changed_public_name])) {

      // The value is casted in integer for
      // https://www.drupal.org/node/2837696.
      $entity
        ->setChangedTime((int) $entity_data['attributes'][$changed_public_name]);
    }
    elseif ($changed_datetime = \DateTime::createFromFormat(\DateTime::RFC3339, $entity_data['attributes'][$changed_public_name])) {
      $entity
        ->setChangedTime($changed_datetime
        ->getTimestamp());
    }
  }
}