Esempio n. 1
0
 /**
  * @param array $config
  *
  * @return bool
  */
 protected function isDisabledItem(array $config)
 {
     $createOnly = isset($config['options']['create_only']) && $config['options']['create_only'];
     // disable config attribute if its value cannot be changed
     if ($createOnly && $this->configModel->getId()) {
         return true;
     }
     // disable field config attribute if its value cannot be changed for some field types
     // an attribute marked as create only should not be disabled on create field page
     if ($this->config->getId() instanceof FieldConfigId && !empty($config['options']['immutable_type']) && in_array($this->config->getId()->getFieldType(), $config['options']['immutable_type'], true) && (!$createOnly || $this->configModel->getId())) {
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     foreach ($this->items as $code => $config) {
         if (isset($config['form']['type'])) {
             $options = isset($config['form']['options']) ? $config['form']['options'] : array();
             $options['config_id'] = $this->config->getId();
             $options['config_is_new'] = $this->configModel->getId() == false;
             /**
              * Disable field on editAction
              */
             if (isset($config['options']['create_only']) && $this->configModel->getId()) {
                 $options['disabled'] = true;
                 $this->appendClassAttr($options, 'disabled-' . $config['form']['type']);
             }
             $propertyOnForm = false;
             $properties = [];
             if (isset($config['options']['required_property'])) {
                 $properties[] = $config['options']['required_property'];
             }
             if (isset($config['options']['required_properties'])) {
                 $properties = array_merge($properties, $config['options']['required_properties']);
             }
             if (!empty($properties)) {
                 foreach ($properties as $property) {
                     if (isset($property['config_id'])) {
                         $configId = $property['config_id'];
                         $fieldName = array_key_exists('field_name', $configId) ? $configId['field_name'] : false;
                         if ($fieldName === false && $this->config->getId() instanceof FieldConfigId) {
                             $fieldName = $this->config->getId()->getFieldName();
                         }
                         $className = isset($configId['class_name']) ? $configId['class_name'] : $this->config->getId()->getClassName();
                         $scope = isset($configId['scope']) ? $configId['scope'] : $this->config->getId()->getScope();
                         if ($fieldName) {
                             $configId = new FieldConfigId($scope, $className, $fieldName, $this->config->getId()->getFieldType());
                         } else {
                             $configId = new EntityConfigId($scope, $className);
                         }
                         //check if requirement property is set in this form
                         if ($className == $this->config->getId()->getClassName()) {
                             if ($fieldName) {
                                 if ($this->config->getId() instanceof FieldConfigId && $this->config->getId()->getFieldName() == $fieldName) {
                                     $propertyOnForm = true;
                                 }
                             } else {
                                 $propertyOnForm = true;
                             }
                         }
                     } else {
                         $propertyOnForm = true;
                         $configId = $this->config->getId();
                     }
                     $requireConfig = $this->configManager->getConfig($configId);
                     if ($requireConfig->get($property['code']) != $property['value']) {
                         if ($propertyOnForm) {
                             $this->appendClassAttr($options, 'hide');
                         } else {
                             continue;
                         }
                     }
                 }
                 if ($propertyOnForm) {
                     $this->setAttr($options, 'data-requireProperty', $configId->toString() . $property['code']);
                     $this->setAttr($options, 'data-requireValue', $property['value']);
                 }
             }
             if (isset($config['constraints'])) {
                 $options['constraints'] = $config['constraints'];
             }
             $this->setAttr($options, 'data-property_id', $this->config->getId()->toString() . $code);
             $builder->add($code, $config['form']['type'], $options);
         }
     }
 }