class SkipImported in Entity Share 8.3
Skip already imported entities.
Plugin annotation
@ImportProcessor(
id = "skip_imported",
label = @Translation("Skip already imported entities"),
description = @Translation("If the entities haven't changed on Remote, this plugin prevents saving of the entities."),
stages = {
"is_entity_importable" = -5,
},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_share_client\ImportProcessor\ImportProcessorPluginBase implements ContainerFactoryPluginInterface, ImportProcessorInterface
- class \Drupal\entity_share_client\Plugin\EntityShareClient\Processor\SkipImported
- class \Drupal\entity_share_client\ImportProcessor\ImportProcessorPluginBase implements ContainerFactoryPluginInterface, ImportProcessorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SkipImported
File
- modules/
entity_share_client/ src/ Plugin/ EntityShareClient/ Processor/ SkipImported.php, line 24
Namespace
Drupal\entity_share_client\Plugin\EntityShareClient\ProcessorView source
class SkipImported extends ImportProcessorPluginBase {
/**
* The Entity import state information service.
*
* @var \Drupal\entity_share_client\Service\StateInformationInterface
*/
protected $stateInformation;
/**
* The resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
*/
protected $resourceTypeRepository;
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
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]);
// Determine public name of 'langcode'.
$langcode_public_name = FALSE;
if ($resource_type
->hasField('langcode')) {
$langcode_public_name = $resource_type
->getPublicName('langcode');
}
$langcode = $entity_data['attributes'][$langcode_public_name] ?? NULL;
// Get the information of the last import of this entity.
$import_status_entity = $this->stateInformation
->getImportStatusByParameters($entity_uuid, $entity_type_id, $langcode);
// If there is no information on when this entity was last imported, it
// means that probably it hasn't been - so it should be importable.
if (!$import_status_entity) {
return TRUE;
}
// Determine public name of 'changed' property.
$changed_public_name = FALSE;
if ($resource_type
->hasField('changed')) {
$changed_public_name = $resource_type
->getPublicName('changed');
}
// Get the remote 'changed' value, if exists:
$remote_changed_time = $entity_data['attributes'][$changed_public_name] ?? FALSE;
// If there is no information on when the remote entity has been modified,
// we shouldn't skip it - so it should be importable.
if ($remote_changed_time === FALSE) {
return TRUE;
}
$remote_changed_timestamp = EntityShareUtility::convertChangedTime($remote_changed_time);
// If the remote entity was modified after our last import, it should
// be importable.
return $import_status_entity
->getLastImport() < $remote_changed_timestamp;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
ImportProcessorInterface:: |
constant | Processing stage: is entity importable. | ||
ImportProcessorInterface:: |
constant | Processing stage: post entity save. | ||
ImportProcessorInterface:: |
constant | Processing stage: prepare entity data. | ||
ImportProcessorInterface:: |
constant | Processing stage: prepare importable entity data. | ||
ImportProcessorInterface:: |
constant | Processing stage: process entity. | ||
ImportProcessorPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
3 |
ImportProcessorPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Returns the plugin's description. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Returns the weight for a specific processing stage. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Determines whether this processor should always be enabled. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Returns the label for use on the administration pages. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Method called on STAGE_POST_ENTITY_SAVE. Overrides ImportProcessorInterface:: |
1 |
ImportProcessorPluginBase:: |
public | function |
Method called on STAGE_PREPARE_ENTITY_DATA. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Method called on STAGE_PREPARE_IMPORTABLE_ENTITY_DATA. Overrides ImportProcessorInterface:: |
4 |
ImportProcessorPluginBase:: |
public | function |
Method called on STAGE_PROCESS_ENTITY. Overrides ImportProcessorInterface:: |
4 |
ImportProcessorPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ImportProcessorPluginBase:: |
public | function |
Sets the weight for a specific processing stage. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function | Form submission handler. | |
ImportProcessorPluginBase:: |
public | function |
Checks whether this processor implements a particular stage. Overrides ImportProcessorInterface:: |
|
ImportProcessorPluginBase:: |
public | function | Form validation handler. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
SkipImported:: |
protected | property | The resource type repository. | |
SkipImported:: |
protected | property | The Entity import state information service. | |
SkipImported:: |
public static | function |
Creates an instance of the plugin. Overrides ImportProcessorPluginBase:: |
|
SkipImported:: |
public | function |
Method called on STAGE_IS_ENTITY_IMPORTABLE. Overrides ImportProcessorPluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |