Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventListener(FormEvents::POST_SUBMIT, function () use($options) {
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $options['config_id'];
         $entityConfig = $this->extendConfigProvider->getConfig($fieldConfigId->getClassName());
         if ($entityConfig->is('state', ExtendScope::STATE_ACTIVE) && !$this->hasRelation($entityConfig, $this->getRelationKey($fieldConfigId))) {
             $entityConfig->set('state', ExtendScope::STATE_UPDATE);
             $this->extendConfigProvider->persist($entityConfig);
             $this->extendConfigProvider->flush();
         }
     });
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventListener(FormEvents::POST_SUBMIT, function () use($options) {
         /** @var FieldConfigId $configId */
         $configId = $options['config_id'];
         $relationKey = ExtendHelper::buildRelationKey($configId->getClassName(), $configId->getFieldName(), 'manyToOne', 'Oro\\Bundle\\AttachmentBundle\\Entity\\File');
         /** @var Config $entityExtendConfig */
         $entityExtendConfig = $this->extendConfigProvider->getConfig($configId->getClassName());
         if ($this->isApplicable($entityExtendConfig, $relationKey)) {
             if ($entityExtendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
                 $entityExtendConfig->set('state', ExtendScope::STATE_UPDATE);
                 $this->extendConfigProvider->persist($entityExtendConfig);
                 $this->extendConfigProvider->flush();
             }
         }
     });
 }
Exemplo n.º 3
0
 /**
  * @param ConfigInterface $extendConfig
  *
  * @return bool
  */
 protected function updateStateValues(ConfigInterface $extendConfig)
 {
     $hasChanges = false;
     $className = $extendConfig->getId()->getClassName();
     $fieldConfigs = $this->configProvider->getConfigs($className, true);
     if ($extendConfig->is('state', ExtendScope::STATE_DELETE)) {
         // mark entity as deleted
         if (!$extendConfig->is('is_deleted')) {
             $extendConfig->set('is_deleted', true);
             $this->configProvider->persist($extendConfig);
             $hasChanges = true;
         }
         // mark all fields as deleted
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->is('is_deleted')) {
                 $fieldConfig->set('is_deleted', true);
                 $this->configProvider->persist($fieldConfig);
                 $hasChanges = true;
             }
         }
     } elseif (!$extendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
         $hasNotActiveFields = false;
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->is('state', ExtendScope::STATE_DELETE) && !$fieldConfig->is('state', ExtendScope::STATE_ACTIVE)) {
                 $hasNotActiveFields = true;
                 break;
             }
         }
         // Set entity state to active if all fields are active or deleted
         if (!$hasNotActiveFields) {
             $extendConfig->set('state', ExtendScope::STATE_ACTIVE);
             $this->configProvider->persist($extendConfig);
         }
         $hasChanges = true;
     }
     if ($hasChanges) {
         $this->configProvider->flush();
     }
 }
Exemplo n.º 4
0
 public function testPersistFlush()
 {
     $this->configProvider->persist($this->entityConfig);
     $this->configProvider->flush();
 }