SkipImported.php in Entity Share 8.3
File
modules/entity_share_client/src/Plugin/EntityShareClient/Processor/SkipImported.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_client\Plugin\EntityShareClient\Processor;
use Drupal\entity_share\EntityShareUtility;
use Drupal\entity_share_client\ImportProcessor\ImportProcessorPluginBase;
use Drupal\entity_share_client\RuntimeImportContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SkipImported extends ImportProcessorPluginBase {
protected $stateInformation;
protected $resourceTypeRepository;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->stateInformation = $container
->get('entity_share_client.state_information');
$instance->resourceTypeRepository = $container
->get('jsonapi.resource_type.repository');
return $instance;
}
public function isEntityImportable(RuntimeImportContext $runtime_import_context, array $entity_data) {
$entity_uuid = $entity_data['id'];
$parsed_type = explode('--', $entity_data['type']);
$entity_type_id = $parsed_type[0];
$resource_type = $this->resourceTypeRepository
->get($parsed_type[0], $parsed_type[1]);
$langcode_public_name = FALSE;
if ($resource_type
->hasField('langcode')) {
$langcode_public_name = $resource_type
->getPublicName('langcode');
}
$langcode = $entity_data['attributes'][$langcode_public_name] ?? NULL;
$import_status_entity = $this->stateInformation
->getImportStatusByParameters($entity_uuid, $entity_type_id, $langcode);
if (!$import_status_entity) {
return TRUE;
}
$changed_public_name = FALSE;
if ($resource_type
->hasField('changed')) {
$changed_public_name = $resource_type
->getPublicName('changed');
}
$remote_changed_time = $entity_data['attributes'][$changed_public_name] ?? FALSE;
if ($remote_changed_time === FALSE) {
return TRUE;
}
$remote_changed_timestamp = EntityShareUtility::convertChangedTime($remote_changed_time);
return $import_status_entity
->getLastImport() < $remote_changed_timestamp;
}
}