You are here

public static function DefaultEntityReferenceHandler::saveEmbeddedPushToPools in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultEntityReferenceHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultEntityReferenceHandler::saveEmbeddedPushToPools()
  2. 2.0.x src/Plugin/cms_content_sync/field_handler/DefaultEntityReferenceHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultEntityReferenceHandler::saveEmbeddedPushToPools()

Save the push settings the user selected for paragraphs.

Parameters

null $parent_entity:

array $tree_position:

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to DefaultEntityReferenceHandler::saveEmbeddedPushToPools()
cms_content_sync_entity_insert in ./cms_content_sync.module
Push the entity automatically if configured to do so.
cms_content_sync_entity_update in ./cms_content_sync.module
Push the entity automatically if configured to do so.

File

src/Plugin/cms_content_sync/field_handler/DefaultEntityReferenceHandler.php, line 73

Class

DefaultEntityReferenceHandler
Providing a minimalistic implementation for any field type.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler

Code

public static function saveEmbeddedPushToPools(EntityInterface $entity, $parent_entity = null, $tree_position = []) {

  // Make sure paragraph push settings are saved as well..
  $entityTypeManager = \Drupal::entityTypeManager();
  $entityFieldManager = \Drupal::service('entity_field.manager');

  /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
  $fields = $entityFieldManager
    ->getFieldDefinitions($entity
    ->getEntityTypeId(), $entity
    ->bundle());
  foreach ($fields as $name => $definition) {
    if ('entity_reference_revisions' == $definition
      ->getType()) {
      $reference_type = $definition
        ->getFieldStorageDefinition()
        ->getPropertyDefinition('entity')
        ->getTargetDefinition()
        ->getEntityTypeId();
      $storage = $entityTypeManager
        ->getStorage($reference_type);
      $data = $entity
        ->get($name)
        ->getValue();
      foreach ($data as $delta => $value) {
        if (empty($value['target_id'])) {
          continue;
        }
        $target_id = $value['target_id'];
        $reference = $storage
          ->load($target_id);
        if (!$reference) {
          continue;
        }

        // In case the values are still present, favor those.
        if (!empty($value['subform']['cms_content_sync_group'])) {
          $set = $value['subform']['cms_content_sync_group'];
          EntityStatus::accessTemporaryPushToPoolInfoForField($entity
            ->getEntityTypeId(), $entity
            ->uuid(), $name, $delta, $tree_position, $set['cms_content_sync_flow'], $set['cms_content_sync_pool'], !empty($set['cms_content_sync_uuid']) ? $set['cms_content_sync_uuid'] : null);
        }
        EntityStatus::saveSelectedPushToPoolForField($entity, $name, $delta, $reference, $tree_position);
        self::saveEmbeddedPushToPools($reference, $entity, array_merge($tree_position, [
          $name,
          $delta,
          'subform',
        ]));
      }
    }
  }
}