class Parents in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/SyncNormalizerDecorator/Parents.php \Drupal\content_sync\Plugin\SyncNormalizerDecorator\Parents
 
Plugin annotation
@SyncNormalizerDecorator(
  id = "parents",
  name = @Translation("Parents"),
)
  Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecorator\Parents implements ContainerFactoryPluginInterface
 
 
 - class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
 
Expanded class hierarchy of Parents
File
- src/
Plugin/ SyncNormalizerDecorator/ Parents.php, line 19  
Namespace
Drupal\content_sync\Plugin\SyncNormalizerDecoratorView source
class Parents extends SyncNormalizerDecoratorBase implements ContainerFactoryPluginInterface {
  protected $entityTypeManager;
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
  }
  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @param array $configuration
   * @param $plugin_id
   * @param $plugin_definition
   *
   * @return static
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager'));
  }
  /**
   * @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 = []) {
    if ($entity
      ->hasField('parent')) {
      $entity_type = $entity
        ->getEntityTypeId();
      $storage = $this->entityTypeManager
        ->getStorage($entity_type);
      if (method_exists($storage, 'loadParents')) {
        $parents = $storage
          ->loadParents($entity
          ->id());
        foreach ($parents as $parent_key => $parent) {
          $normalized_entity['parent'][] = [
            'target_type' => $entity_type,
            'target_uuid' => $parent
              ->uuid(),
          ];
          $normalized_entity['_content_sync']['entity_dependencies'][$entity_type][] = $entity_type . "." . $parent
            ->bundle() . "." . $parent
            ->uuid();
        }
      }
      elseif (method_exists($entity, 'getParentId')) {
        $parent_id = $entity
          ->getParentId();
        if (($tmp = strstr($parent_id, ':')) !== false) {
          $parent_uuid = substr($tmp, 1);
          $parents = $storage
            ->loadByProperties([
            'uuid' => $parent_uuid,
          ]);
          $parent = !empty($parents) ? reset($parents) : null;
          if (!empty($parent)) {
            $normalized_entity['parent'][] = [
              'target_type' => $entity_type,
              'target_uuid' => $parent_uuid,
            ];
            $normalized_entity['_content_sync']['entity_dependencies'][$entity_type][] = $entity_type . "." . $parent
              ->bundle() . "." . $parent_uuid;
          }
        }
      }
    }
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            Parents:: | 
                  protected | property | ||
| 
            Parents:: | 
                  public static | function | 
            Overrides ContainerFactoryPluginInterface:: | 
                  |
| 
            Parents:: | 
                  public | function | 
            Overrides SyncNormalizerDecoratorBase:: | 
                  |
| 
            Parents:: | 
                  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:: |