38 $this->storage = $entity_type_manager->getStorage(
'paragraph');
39 $this->fieldValueManager = $field_value_manager;
59 $item = $buffer->getItem($paragraph_uuid);
68 if ($paragraph->getParentEntity() == $context->
getEntity()) {
69 $item = $buffer->createItem($paragraph);
102 protected function createEntityMap(ParagraphInterface $entity1, ParagraphInterface $entity2, array &$map) {
103 $map[$entity1->uuid()] = $entity2->uuid();
105 if ($entity1->bundle() != $entity2->bundle()) {
106 throw new \Exception(
'mismatch');
108 foreach ($entity1->getFields() as $field) {
109 $field_definition = $field->getFieldDefinition();
110 $field_name = $field_definition->getName();
111 if (!isset($entity2->{$field_name})) {
112 throw new \Exception(
'mismatch');
115 if ($this->fieldValueManager->isParagraphsField($field_definition)) {
116 $items1 = $entity1->{$field_name};
117 $items2 = $entity2->{$field_name};
119 if (count($items1) != count($items2)) {
120 throw new \Exception(
'mismatch');
123 foreach ($items1 as $delta => $item) {
124 $cmp_entity1 = $items1[$delta]->entity;
125 $cmp_entity2 = $items2[$delta]->entity;
142 $paragraph = $this->storage->create([
143 'type' => $bundle_name,
158 $entities = $this->storage->loadByProperties([
'uuid' => $paragraph_uuid]);
159 $entity = reset($entities);
160 return $entity ? $entity : NULL;
createParagraph($bundle_name)
addAdditionalContext($key, $value)
duplicateBufferItem(CommandContextInterface $context, EditBufferItemInterface $item)
getParagraph($paragraph_uuid)
__construct(EntityTypeManagerInterface $entity_type_manager, FieldValueManagerInterface $field_value_manager)
getBufferItem(CommandContextInterface $context, $paragraph_uuid)
createEntityMap(ParagraphInterface $entity1, ParagraphInterface $entity2, array &$map)
createBufferItem(CommandContextInterface $context, $bundle_name)