class IdsCleaner in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/SyncNormalizerDecorator/IdsCleaner.php \Drupal\content_sync\Plugin\SyncNormalizerDecorator\IdsCleaner
Provides a decorator for setting the alias to entity.
Plugin annotation
@SyncNormalizerDecorator(
id = "id_cleaner",
name = @Translation("IDs Cleaner"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecorator\IdsCleaner
- class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
Expanded class hierarchy of IdsCleaner
File
- src/
Plugin/ SyncNormalizerDecorator/ IdsCleaner.php, line 17
Namespace
Drupal\content_sync\Plugin\SyncNormalizerDecoratorView source
class IdsCleaner extends SyncNormalizerDecoratorBase {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* @param array $normalized_entity
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* @param $format
* @param array $context
*/
public function decorateNormalization(array &$normalized_entity, ContentEntityInterface $entity, $format, array $context = []) {
$this
->cleanReferenceIds($normalized_entity, $entity);
$this
->cleanIds($normalized_entity, $entity);
}
/**
* @param $normalized_entity
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
*
* @return mixed
*/
protected function cleanReferenceIds(&$normalized_entity, ContentEntityInterface $entity) {
$field_definitions = $entity
->getFieldDefinitions();
foreach ($field_definitions as $field_name => $field_definition) {
// We are only interested in importing content entities.
if (!is_a($field_definition
->getClass(), '\\Drupal\\Core\\Field\\EntityReferenceFieldItemList', TRUE)) {
continue;
}
if (isset($normalized_entity[$field_name]) && !empty($normalized_entity[$field_name]) && is_array($normalized_entity[$field_name])) {
$entity_type = $field_definition
->getFieldStorageDefinition()
->getSetting('target_type');
$reflection = new \ReflectionClass(\Drupal::entityTypeManager()
->getDefinition($entity_type)
->getClass());
if (!$reflection
->implementsInterface('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
continue;
}
$key = $field_definition
->getFieldStorageDefinition()
->getMainPropertyName();
foreach ($normalized_entity[$field_name] as &$item) {
if (!empty($item[$key])) {
unset($item[$key]);
}
if (!empty($item['url'])) {
unset($item['url']);
}
}
}
}
return $normalized_entity;
}
/**
* @param $normalized_entity
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
*
* @return mixed
*/
protected function cleanIds(&$normalized_entity, ContentEntityInterface $entity) {
$keys = $entity
->getEntityType()
->getKeys();
if (isset($normalized_entity[$keys['id']])) {
unset($normalized_entity[$keys['id']]);
}
if (isset($keys['revision']) && isset($normalized_entity[$keys['revision']])) {
unset($normalized_entity[$keys['revision']]);
}
return $normalized_entity;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IdsCleaner:: |
protected | function | ||
IdsCleaner:: |
protected | function | ||
IdsCleaner:: |
public | function |
Overrides SyncNormalizerDecoratorBase:: |
|
IdsCleaner:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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. | |
SyncNormalizerDecoratorBase:: |
public | function |
Apply decoration for the denormalization process. Overrides SyncNormalizerDecoratorInterface:: |
|
SyncNormalizerDecoratorBase:: |
public | function |
Apply decoration to the entity after the denormalization process is done. Overrides SyncNormalizerDecoratorInterface:: |