/** * Creates a table that is used to store enum values for the enum with the given code. * * @param Schema $schema * @param string $enumCode The unique identifier of an enum * @param bool $isMultiple Indicates whether several options can be selected for this enum * or it supports only one selected option * @param bool $isPublic Indicates whether this enum can be used by any entity or * it is designed to use in one entity only * @param bool|string[] $immutable Indicates whether the changing the list of enum values and * public flag is allowed or not. More details can be found * in entity_config.yml * @param array $options * * @return Table A table that is used to store enum values * * @throws \InvalidArgumentException * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function createEnum(Schema $schema, $enumCode, $isMultiple = false, $isPublic = false, $immutable = false, array $options = []) { if ($enumCode !== ExtendHelper::buildEnumCode($enumCode)) { new \InvalidArgumentException(sprintf('The enum code "%s" must contain only lower alphabetical symbols, numbers and underscore.', $enumCode)); } $tableName = $this->nameGenerator->generateEnumTableName($enumCode); $className = ExtendHelper::buildEnumValueClassName($enumCode); $options = array_replace_recursive([ExtendOptionsManager::MODE_OPTION => ConfigModelManager::MODE_HIDDEN, ExtendOptionsManager::ENTITY_CLASS_OPTION => $className, 'entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode), 'plural_label' => ExtendHelper::getEnumTranslationKey('plural_label', $enumCode), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode)], 'extend' => ['owner' => ExtendScope::OWNER_SYSTEM, 'is_extend' => true, 'table' => $tableName, 'inherit' => ExtendHelper::BASE_ENUM_VALUE_CLASS], 'enum' => ['code' => $enumCode, 'public' => $isPublic, 'multiple' => $isMultiple]], $options); if ($immutable) { $options['enum']['immutable'] = true; } $table = $schema->createTable($tableName); $this->entityMetadataHelper->registerEntityClass($tableName, $className); $table->addOption(OroOptions::KEY, $options); $table->addColumn('id', 'string', ['length' => ExtendHelper::MAX_ENUM_VALUE_ID_LENGTH, OroOptions::KEY => ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'id'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'id')], 'importexport' => ['identity' => true]]]); $table->addColumn('name', 'string', ['length' => 255, OroOptions::KEY => ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'name'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'name')], 'datagrid' => ['is_visible' => false]]]); $table->addColumn('priority', 'integer', [OroOptions::KEY => ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'priority'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'priority')], 'datagrid' => ['is_visible' => false]]]); $table->addColumn('is_default', 'boolean', [OroOptions::KEY => [ExtendOptionsManager::FIELD_NAME_OPTION => 'default', 'entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'default'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'default')], 'datagrid' => ['is_visible' => false]]]); $table->setPrimaryKey(['id']); return $table; }