示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * @dataProvider hasOtherReferencesProvider
  */
 public function testHasOtherReferencesWithNoRefs($enumType)
 {
     $enumCode = 'test_enum';
     $config1 = new Config(new EntityConfigId('extend', 'Test\\Entity1'));
     $config1->set('is_extend', true);
     $config2 = new Config(new EntityConfigId('extend', 'Test\\Entity2'));
     $config1Field1 = new Config(new FieldConfigId('enum', 'Test\\Entity1', 'field1', $enumType));
     $config1Field1->set('enum_code', $enumCode);
     $config1Field2 = new Config(new FieldConfigId('enum', 'Test\\Entity1', 'field2', $enumType));
     $config1Field2->set('enum_code', 'another_enum');
     $configs = [$config1, $config2];
     $fieldConfigs = [$config1Field1, $config1Field2];
     $extendConfigProvider = $this->getConfigProviderMock();
     $enumConfigProvider = $this->getConfigProviderMock();
     $this->configManager->expects($this->exactly(2))->method('getProvider')->will($this->returnValueMap([['enum', $enumConfigProvider], ['extend', $extendConfigProvider]]));
     $extendConfigProvider->expects($this->once())->method('getConfigs')->will($this->returnValue($configs));
     $enumConfigProvider->expects($this->once())->method('getConfigs')->with('Test\\Entity1')->will($this->returnValue($fieldConfigs));
     $this->assertFalse($this->typeHelper->hasOtherReferences($enumCode, 'Test\\Entity1', 'field1'));
 }