本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Config\ConfigManager::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigManager::getConfig方法的具体用法?PHP ConfigManager::getConfig怎么用?PHP ConfigManager::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Config\ConfigManager
的用法示例。
在下文中一共展示了ConfigManager::getConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSubmit
/**
* POST_SUBMIT event handler
*
* @param FormEvent $event
*/
public function postSubmit(FormEvent $event)
{
$form = $event->getForm();
$options = $form->getConfig()->getOptions();
/** @var ConfigIdInterface $configId */
$configId = $options['config_id'];
if (!$form->isValid()) {
return;
}
// change the entity state to "Requires update" if the attribute has "require_schema_update" option
// and the value of the attribute was changed
$configProvider = $this->configManager->getProvider($configId->getScope());
if ($configProvider->getPropertyConfig()->isSchemaUpdateRequired($form->getName(), $configId)) {
$newVal = $form->getData();
$oldVal = $this->configManager->getConfig($configId)->get($form->getName());
if ($this->isSchemaUpdateRequired($newVal, $oldVal)) {
$extendConfigProvider = $this->configManager->getProvider('extend');
$extendConfig = $extendConfigProvider->getConfig($configId->getClassName());
if ($extendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
$extendConfig->set('state', ExtendScope::STATE_UPDATE);
$this->configManager->persist($extendConfig);
}
}
}
}
示例2: getGroupedResults
/**
* Returns grouped search results
*
* @param string $string
* @return array
*/
public function getGroupedResults($string)
{
$search = $this->getResults($string);
// empty key array contains all data
$result = array('' => array('count' => 0, 'class' => '', 'config' => array(), 'icon' => '', 'label' => ''));
/** @var $item Item */
foreach ($search->getElements() as $item) {
$config = $item->getEntityConfig();
$alias = $config['alias'];
if (!isset($result[$alias])) {
$group = array('count' => 0, 'class' => $item->getEntityName(), 'config' => $config, 'icon' => '', 'label' => '');
if (!empty($group['class']) && $this->configManager->hasConfig($group['class'])) {
$entityConfigId = new EntityConfigId('entity', $group['class']);
$entityConfig = $this->configManager->getConfig($entityConfigId);
if ($entityConfig->has('plural_label')) {
$group['label'] = $this->translator->trans($entityConfig->get('plural_label'));
}
if ($entityConfig->has('icon')) {
$group['icon'] = $entityConfig->get('icon');
}
}
$result[$alias] = $group;
}
$result[$alias]['count']++;
$result['']['count']++;
}
uasort($result, function ($first, $second) {
if ($first['label'] == $second['label']) {
return 0;
}
return $first['label'] > $second['label'] ? 1 : -1;
});
return $result;
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$configModel = $options['config_model'];
$data = array();
if ($configModel instanceof FieldConfigModel) {
$className = $configModel->getEntity()->getClassName();
$fieldName = $configModel->getFieldName();
$fieldType = $configModel->getType();
$configType = PropertyConfigContainer::TYPE_FIELD;
/**
* Add read only field name and field type
*/
$builder->add('fieldName', 'text', array('label' => 'oro.entity_config.form.name.label', 'block' => 'general', 'disabled' => true, 'data' => $fieldName));
$builder->add('type', 'choice', array('label' => 'oro.entity_config.form.type.label', 'choices' => [], 'block' => 'general', 'disabled' => true, 'empty_value' => 'oro.entity_extend.form.data_type.' . $fieldType));
} else {
$className = $configModel->getClassName();
$fieldName = null;
$fieldType = null;
$configType = PropertyConfigContainer::TYPE_ENTITY;
}
foreach ($this->configManager->getProviders() as $provider) {
if ($provider->getPropertyConfig()->hasForm($configType, $fieldType)) {
$config = $this->configManager->getConfig($provider->getId($className, $fieldName, $fieldType));
$builder->add($provider->getScope(), new ConfigScopeType($provider->getPropertyConfig()->getFormItems($configType, $fieldType), $config, $this->configManager, $configModel), array('block_config' => $this->getFormBlockConfig($provider, $configType)));
$data[$provider->getScope()] = $config->all();
}
}
$builder->setData($data);
$builder->addEventSubscriber(new ConfigSubscriber($this->doctrine, $this->configManager, $this->translator, $this->dbTranslationMetadataCache));
}
示例4: getEntityChoiceList
/**
* @param string $entityClassName
* @param string $relationType
*
* @return array
*/
protected function getEntityChoiceList($entityClassName, $relationType)
{
/** @var EntityConfigId[] $entityIds */
$entityIds = $this->targetEntityClass ? [$this->configManager->getId('extend', $this->targetEntityClass)] : $this->configManager->getIds('extend');
if (in_array($relationType, [RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY], true)) {
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return $config->is('is_extend');
});
}
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return !$config->is('state', ExtendScope::STATE_NEW) && ($this->targetEntityClass || !$config->is('is_deleted'));
});
$choices = [];
foreach ($entityIds as $entityId) {
$className = $entityId->getClassName();
if (!$this->configManager->hasConfig($className, 'id') && !ExtendHelper::isCustomEntity($className)) {
// @todo: temporary ignore entities that don't have PK with name 'id'
// remove this in https://magecore.atlassian.net/browse/BAP-9713
continue;
}
if ($className !== $entityClassName) {
$entityConfig = $this->configManager->getProvider('entity')->getConfig($className);
$choices[$className] = $entityConfig->get('label');
}
}
return $choices;
}
示例5: getEntityChoiceList
protected function getEntityChoiceList($entityClassName, $relationType)
{
$choices = array();
$extendEntityConfig = $this->configManager->getProvider('extend');
/** @var EntityConfigId[] $entityIds */
$entityIds = $this->targetEntity ? array($extendEntityConfig->getId($this->targetEntity)) : $extendEntityConfig->getIds();
if (in_array($relationType, array(RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY))) {
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return $config->is('is_extend');
});
}
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return $config->is('is_extend', false) || !$config->is('state', ExtendScope::STATE_NEW);
});
foreach ($entityIds as $entityId) {
$className = $entityId->getClassName();
if ($className != $entityClassName) {
$entityConfig = $this->configManager->getProvider('entity')->getConfig($className);
$choices[$className] = new ChoiceListItem($entityConfig->get('label'), array('data-icon' => $entityConfig->get('icon')));
}
}
return $choices;
}
示例6: getEntityChoiceList
protected function getEntityChoiceList($entityClassName, $relationType)
{
$choices = [];
$extendEntityConfig = $this->configManager->getProvider('extend');
/** @var EntityConfigId[] $entityIds */
$entityIds = $this->targetEntity ? [$extendEntityConfig->getId($this->targetEntity)] : $extendEntityConfig->getIds();
if (in_array($relationType, [RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY], true)) {
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return $config->is('is_extend');
});
}
$entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
$config = $this->configManager->getConfig($configId);
return !$config->is('state', ExtendScope::STATE_NEW) && ($this->targetEntity || !$config->is('is_deleted'));
});
foreach ($entityIds as $entityId) {
$className = $entityId->getClassName();
if ($className !== $entityClassName) {
$entityConfig = $this->configManager->getProvider('entity')->getConfig($className);
$choices[$className] = $entityConfig->get('label');
}
}
return $choices;
}
示例7: getClassConfigValue
/**
* @param string $className The entity class name
* @param string $attrName The entity config attribute name
* @param string $scope The entity config scope name
*
* @return mixed
*/
public function getClassConfigValue($className, $attrName, $scope = 'entity')
{
if (!$this->configManager->hasConfig($className)) {
return null;
}
$entityConfig = new EntityConfigId($scope, $className);
return $this->configManager->getConfig($entityConfig)->get($attrName);
}
示例8: testCreateConfigFieldModel
public function testCreateConfigFieldModel()
{
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int');
$model = $this->createFieldConfigModel($this->createEntityConfigModel(self::ENTITY_CLASS), 'id', 'int');
$this->modelManager->expects($this->once())->method('findFieldModel')->with(self::ENTITY_CLASS, 'id')->will($this->returnValue(null));
$this->modelManager->expects($this->once())->method('createFieldModel')->with(self::ENTITY_CLASS, 'id', 'int', ConfigModelManager::MODE_DEFAULT)->will($this->returnValue($model));
$metadata = new EntityMetadata(self::ENTITY_CLASS);
$idFieldMetadata = new FieldMetadata(self::ENTITY_CLASS, 'id');
$metadata->addPropertyMetadata($idFieldMetadata);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->will($this->returnValue($metadata));
$idFieldMetadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal'];
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->will($this->returnValue($metadata));
$propertyConfigContainer = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
$propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD, 'int')->will($this->returnValue(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']));
$propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->will($this->returnValue(['translatable', 'translatable10', 'auto_generated']));
$this->configProvider->expects($this->any())->method('getPropertyConfig')->will($this->returnValue($propertyConfigContainer));
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::NEW_FIELD_CONFIG, new FieldConfigEvent(self::ENTITY_CLASS, 'id', $this->configManager));
$config = new Config($configId);
$config->set('other10', 'otherVal10');
$config->set('translatable10', 'labelVal10');
$config->set('other', 'otherVal');
$config->set('translatable', 'labelVal');
$config->set('auto_generated', 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated');
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int');
$this->assertEquals($model, $result);
$this->assertEquals([$config], $this->configManager->getUpdateConfig());
// test that a config for a created model is stored in a local cache
$result = $this->configManager->getConfig($configId);
$this->assertEquals($config, $result);
}
示例9: getMetadataFor
/**
* {@inheritdoc}
*/
public function getMetadataFor($object)
{
$metadata = [];
if ($object instanceof EntityManagerAwareInterface) {
$entityFQCN = $object->getManager()->getMetadata()->name;
$metadata['entity'] = [];
$metadata['entity']['phpType'] = $entityFQCN;
if ($this->cm->hasConfig($entityFQCN)) {
$config = $this->cm->getConfig(new EntityConfigId('entity', $entityFQCN));
$metadata['entity']['label'] = $this->translator->trans($config->get('label'));
$metadata['entity']['pluralLabel'] = $this->translator->trans($config->get('plural_label'));
$metadata['entity']['description'] = $this->translator->trans($config->get('description'));
}
}
return $metadata;
}
示例10: getConfigById
/**
* {@inheritdoc}
*/
public function getConfigById(ConfigIdInterface $configId)
{
if ($configId instanceof FieldConfigId) {
return $this->configManager->getConfig($this->getId($configId->getClassName(), $configId->getFieldName()));
} else {
return $this->configManager->getConfig($this->getId($configId->getClassName()));
}
}
示例11: getClassLabel
/**
* @param string $className
* @return null|string
*/
protected function getClassLabel($className)
{
if (!$this->configManager->hasConfig($className)) {
return null;
}
$entityConfig = new EntityConfigId('entity', $className);
$label = $this->configManager->getConfig($entityConfig)->get('label');
return $this->translator->trans($label);
}
示例12: testConfigChangeSet
public function testConfigChangeSet()
{
$configId = new EntityConfigId('entity', self::ENTITY_CLASS);
$originalConfig = $this->getConfig($configId, ['item1' => true, 'item11' => true, 'item12' => true, 'item2' => 123, 'item21' => 123, 'item22' => 123, 'item3' => 'val2', 'item4' => 'val4', 'item6' => null, 'item7' => 'val7']);
$this->configCache->expects($this->once())->method('getEntityConfig')->willReturn($originalConfig);
$this->configManager->getConfig($configId);
$changedConfig = $this->getConfig($configId, ['item1' => true, 'item11' => 1, 'item12' => false, 'item2' => 123, 'item21' => '123', 'item22' => 456, 'item3' => 'val21', 'item5' => 'val5', 'item6' => 'val6', 'item7' => null]);
$this->configManager->persist($changedConfig);
$this->configManager->calculateConfigChangeSet($changedConfig);
$this->assertEquals(['item12' => [true, false], 'item22' => [123, 456], 'item3' => ['val2', 'val21'], 'item5' => [null, 'val5'], 'item6' => [null, 'val6'], 'item7' => ['val7', null]], $this->configManager->getConfigChangeSet($changedConfig));
}
示例13: prepareEvent
/**
* @param FormEvent $event
* @return array
*/
protected function prepareEvent(FormEvent $event)
{
$formData = $event->getForm()->getRoot()->getData();
if (!$formData) {
return;
}
$entityId = $formData->getId();
$fieldConfigId = $event->getForm()->getConfig()->getOption('config_id');
$extendConfig = $this->configManager->getConfig($fieldConfigId);
$model = $this->configManager->getConfigFieldModel($fieldConfigId->getClassName(), $fieldConfigId->getFieldName());
return [$entityId, $model, $extendConfig];
}
示例14: getEnumDefaultValue
/**
* Gets a default option of an enum associated with the given field
* This method must be public because it is used as a callback
*
* @param string $fieldName
*
* @return string|null
*/
public function getEnumDefaultValue($fieldName)
{
if (isset($this->computedDefaultValues[$fieldName]) || array_key_exists($fieldName, $this->computedDefaultValues)) {
return $this->computedDefaultValues[$fieldName];
}
$fieldConfig = $this->configManager->getConfig(new FieldConfigId('extend', self::CALENDAR_PROPERTY_CLASS, $fieldName, 'enum'));
$repo = $this->doctrineHelper->getEntityRepository($fieldConfig->get('target_entity'));
$data = $repo->createQueryBuilder('e')->select('e.id')->where('e.default = true')->getQuery()->getArrayResult();
if ($data) {
$data = array_shift($data);
}
$result = $data ? $data['id'] : null;
$this->computedDefaultValues[$fieldName] = $result;
return $result;
}
示例15: testGetConfigNotCached
/**
* @dataProvider getConfigNotCachedProvider
*/
public function testGetConfigNotCached($configId, $getModelResult, $expectedConfig)
{
$this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true);
$this->configCache->expects($this->once())->method('getConfigurable')->with(self::ENTITY_CLASS)->willReturn(true);
$this->configCache->expects($this->once())->method('getConfig')->with($this->identicalTo($configId))->willReturn(null);
$this->configCache->expects($this->once())->method('saveConfig')->with($this->equalTo($expectedConfig));
if ($configId instanceof FieldConfigId) {
$this->modelManager->expects($this->never())->method('getEntityModel');
$this->modelManager->expects($this->once())->method('getFieldModel')->with($configId->getClassName(), $configId->getFieldName())->willReturn($getModelResult);
} else {
$this->modelManager->expects($this->once())->method('getEntityModel')->with($configId->getClassName())->willReturn($getModelResult);
$this->modelManager->expects($this->never())->method('getFieldModel');
}
$result = $this->configManager->getConfig($configId);
$this->assertEquals($expectedConfig, $result);
}