コード例 #1
0
 /**
  * Checks if the given constraint is applied or not
  *
  * @param Options     $options
  * @param string|null $constraintName Can be: null, 'add', 'delete'
  *
  * @return bool
  */
 protected function isDisabled($options, $constraintName = null)
 {
     /** @var ConfigIdInterface $configId */
     $configId = $options['config_id'];
     $className = $configId->getClassName();
     if (empty($className)) {
         return false;
     }
     $fieldName = $this->typeHelper->getFieldName($configId);
     if (empty($fieldName)) {
         return false;
     }
     $enumCode = $this->typeHelper->getEnumCode($className, $fieldName);
     if (!empty($enumCode)) {
         if ($options['config_is_new']) {
             // a new field reuses public enum
             return true;
         }
         if ($constraintName) {
             $enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
             if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, $constraintName)) {
                 // is immutable
                 return true;
             }
         }
     }
     return false;
 }
コード例 #2
0
ファイル: EnumPublicType.php プロジェクト: Maksold/platform
 /**
  * Checks if the form type should be read-only or not
  *
  * @param Options $options
  *
  * @return bool
  */
 protected function isReadOnly($options)
 {
     /** @var ConfigIdInterface $configId */
     $configId = $options['config_id'];
     $className = $configId->getClassName();
     if (empty($className)) {
         return false;
     }
     $fieldName = $this->typeHelper->getFieldName($configId);
     if (empty($fieldName)) {
         return false;
     }
     if ($this->typeHelper->isSystem($className, $fieldName)) {
         // it is a system field
         return true;
     }
     $enumCode = $this->typeHelper->getEnumCode($className, $fieldName);
     if (!empty($enumCode)) {
         if ($options['config_is_new']) {
             // a new field reuses public enum
             return true;
         }
         $enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
         if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, 'public')) {
             // is immutable
             return true;
         }
         if ($this->typeHelper->hasOtherReferences($enumCode, $className, $fieldName)) {
             // an enum is reused by other fields
             return true;
         }
     }
     return false;
 }
コード例 #3
0
 public function testGetEnumCodeForField()
 {
     $enumCode = 'test_enum';
     $className = 'Test\\Entity';
     $fieldName = 'testField';
     $config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('get')->with('enum_code')->will($this->returnValue($enumCode));
     $configProvider = $this->getConfigProviderMock();
     $this->configManager->expects($this->once())->method('getProvider')->with('enum')->will($this->returnValue($configProvider));
     $configProvider->expects($this->once())->method('hasConfig')->with($className, $fieldName)->will($this->returnValue(true));
     $configProvider->expects($this->once())->method('getConfig')->with($className, $fieldName)->will($this->returnValue($config));
     $this->assertEquals($enumCode, $this->typeHelper->getEnumCode($className, $fieldName));
 }