Beispiel #1
0
 /**
  * @param AccessorInterface $accessor
  * @throws InvalidArgumentException
  */
 public function add(AccessorInterface $accessor)
 {
     if ($accessor === $this) {
         throw new InvalidArgumentException("Cannot add accessor to itself.");
     }
     $this->elements[$accessor->getName()] = $accessor;
 }
Beispiel #2
0
 /**
  * Render value of merge field
  *
  * @param FieldData $fieldData
  * @param int $entityOffset
  * @return string
  */
 public function renderMergeFieldValue(FieldData $fieldData, $entityOffset)
 {
     $entity = $fieldData->getEntityData()->getEntityByOffset($entityOffset);
     $metadata = $fieldData->getMetadata();
     $value = $this->accessor->getValue($entity, $metadata);
     return $this->fieldValueRenderer->renderFieldValue($value, $metadata, $entity);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $fieldMetadata = $fieldData->getMetadata();
     $sourceEntity = $fieldData->getSourceEntity();
     $value = $this->accessor->getValue($sourceEntity, $fieldMetadata);
     $this->accessor->setValue($masterEntity, $fieldMetadata, $value);
 }
 /**
  * @param FieldDataEvent $event
  */
 public function afterMergeField(FieldDataEvent $event)
 {
     $fieldData = $event->getFieldData();
     $metadata = $fieldData->getMetadata();
     if (MergeModes::REPLACE != $fieldData->getMode() || !$metadata->hasDoctrineMetadata() || !$metadata->getDoctrineMetadata()->isAssociation() || !$metadata->isDefinedBySourceEntity() || $metadata->isCollection() || !in_array('remove', (array) $metadata->getDoctrineMetadata()->get('cascade'))) {
         return;
     }
     $entitiesToClear = $this->getEntitiesToClear($fieldData->getEntityData());
     foreach ($entitiesToClear as $entityToClear) {
         $this->accessor->setValue($entityToClear, $metadata, null);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $fieldMetadata = $fieldData->getMetadata();
     $sourceEntity = $fieldData->getSourceEntity();
     //for fields that are not in the merge form(system, custom etc) use values from Master record
     if (!$sourceEntity) {
         $sourceEntity = $masterEntity;
     }
     $value = $this->accessor->getValue($sourceEntity, $fieldMetadata);
     $this->accessor->setValue($masterEntity, $fieldMetadata, $value);
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $fieldMetadata = $fieldData->getMetadata();
     $entities = $entityData->getEntities();
     $relatedEntities = [];
     foreach ($entities as $entity) {
         $values = $this->accessor->getValue($entity, $fieldMetadata);
         foreach ($values as $value) {
             $key = $this->doctrineHelper->getEntityIdentifierValue($value);
             $relatedEntities[$key] = $value;
         }
     }
     $collection = new ArrayCollection(array_values($relatedEntities));
     $this->accessor->setValue($masterEntity, $fieldMetadata, $collection);
 }