/**
  * Return available in template variables
  *
  * @param string $entityName
  * @return array
  */
 public function getTemplateVariables($entityName)
 {
     $userClassName = $this->getUser() ? get_class($this->getUser()) : false;
     $allowedData = array('entity' => array(), 'user' => array());
     $ids = $this->configProvider->getIds();
     foreach ($ids as $entityConfigId) {
         // export variables of asked entity and current user entity class
         $className = $entityConfigId->getClassName();
         if ($className == $entityName || $className == $userClassName) {
             $fields = $this->configProvider->filter(function (ConfigInterface $config) {
                 return $config->is('available_in_template');
             }, $className);
             $fields = array_values(array_map(function (ConfigInterface $field) {
                 return $field->getId()->getFieldName();
             }, $fields));
             switch ($className) {
                 case $entityName:
                     $allowedData['entity'] = $fields;
                     break;
                 case $userClassName:
                     $allowedData['user'] = $fields;
                     break;
             }
             if ($entityName == $userClassName) {
                 $allowedData['user'] = $allowedData['entity'];
             }
         }
     }
     return $allowedData;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $fields = [];
     $className = $options['className'];
     $fieldConfigIds = $this->entityProvider->getIds($className);
     /** @var FieldConfigId $fieldConfigId */
     foreach ($fieldConfigIds as $fieldConfigId) {
         if ($fieldConfigId->getFieldType() === RelationTypeBase::TO_MANY) {
             continue;
         }
         $fieldName = $fieldConfigId->getFieldName();
         $fields[$fieldName] = $this->entityProvider->getConfig($className, $fieldName)->get('label', false, ucfirst($fieldName));
     }
     $builder->add('keys', 'collection', array('required' => true, 'type' => new UniqueKeyType($fields), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_name' => 'tag__name__', 'label' => false, 'constraints' => [new UniqueKeys()]));
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getMetadata()
 {
     $metadata = parent::getMetadata();
     $entityIds = [];
     $configIds = $this->entityConfigProvider->getIds();
     foreach ($configIds as $configId) {
         $className = $configId->getClassName();
         if ($this->extendConfigProvider->getConfig($className)->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_UPDATE])) {
             $classMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
             $identifiers = $classMetadata->getIdentifier();
             $entityIds[$className] = array_shift($identifiers);
         }
     }
     $metadata['entity_ids'] = $entityIds;
     return $metadata;
 }
Exemplo n.º 4
0
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $entityClass = $form->getConfig()->getDataClass();
     /** @var FieldConfigId[] $fieldConfigIds */
     $fieldConfigIds = $this->extendConfigProvider->getIds($entityClass);
     foreach ($fieldConfigIds as $fieldConfigId) {
         if ($fieldConfigId->getFieldType() === 'manyToOne') {
             $fieldEntityConfig = $this->entityConfigProvider->getConfigById($fieldConfigId);
             $fieldExtendConfig = $this->extendConfigProvider->getConfigById($fieldConfigId);
             if (!$fieldExtendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
                 continue;
             }
             $form->add($fieldConfigId->getFieldName(), 'entity', ['required' => false, 'class' => $fieldExtendConfig->get('target_entity'), 'property' => $fieldExtendConfig->get('target_field'), 'label' => $fieldEntityConfig->get('label')]);
         }
     }
 }
 /**
  * Prepare configuration from entity config
  *
  * @return array
  */
 private function prepareConfiguration()
 {
     $configuration = array();
     foreach ($this->configProvider->getIds() as $entityConfigId) {
         $className = $entityConfigId->getClassName();
         $fields = $this->configProvider->filter(function (ConfigInterface $fieldConfig) {
             return $fieldConfig->is('available_in_template');
         }, $className);
         if (count($fields)) {
             $configuration[$className] = array();
             foreach ($fields as $fieldConfig) {
                 $configuration[$className][] = 'get' . strtolower($fieldConfig->getId()->getFieldName());
             }
         }
     }
     return $configuration;
 }
 /**
  * {@inheritdoc}
  */
 public function getVariableGetters($entityClass = null)
 {
     if ($entityClass) {
         // process the specified entity only
         return $this->getEntityVariableGetters($entityClass);
     }
     // process all entities
     $result = [];
     $entityIds = $this->entityConfigProvider->getIds();
     foreach ($entityIds as $entityId) {
         $className = $entityId->getClassName();
         $entityData = $this->getEntityVariableGetters($className);
         if (!empty($entityData)) {
             $result[$className] = $entityData;
         }
     }
     return $result;
 }
 public function testGetConfigs()
 {
     $this->configManager->expects($this->exactly(4))->method('getIds')->with('testScope', DemoEntity::ENTITY_NAME)->will($this->returnValue(array($this->entityConfig->getId())));
     $this->assertEquals(array($this->entityConfig->getId()), $this->configProvider->getIds(DemoEntity::ENTITY_NAME));
     $this->assertEquals(array($this->entityConfig), $this->configProvider->getConfigs(DemoEntity::ENTITY_NAME));
     $this->assertEquals(array(), $this->configProvider->filter(function (ConfigInterface $config) {
         return $config->getId()->getScope() == 'wrongScope';
     }, DemoEntity::ENTITY_NAME));
     $entityConfig = new Config(new EntityConfigId(DemoEntity::ENTITY_NAME, 'testScope'));
     $entityConfig->set('key', 'value');
     $this->assertEquals(array($entityConfig), $this->configProvider->map(function (ConfigInterface $config) {
         return $config->set('key', 'value');
     }, DemoEntity::ENTITY_NAME));
 }
 /**
  * Return mapping data for entities that has one-way link to $className entity
  *
  * @param string $className
  *
  * @return array
  */
 protected function getUnidirectionalRelations($className)
 {
     $relations = [];
     /** @var EntityConfigId[] $entityConfigIds */
     $entityConfigIds = $this->entityConfigProvider->getIds();
     foreach ($entityConfigIds as $entityConfigId) {
         if ($this->isIgnoredEntity($entityConfigId)) {
             continue;
         }
         $metadata = $this->getMetadataFor($entityConfigId->getClassName());
         $targetMappings = $metadata->getAssociationMappings();
         if (empty($targetMappings)) {
             continue;
         }
         foreach ($targetMappings as $mapping) {
             if ($mapping['isOwningSide'] && empty($mapping['inversedBy']) && $mapping['targetEntity'] === $className) {
                 $relations[$mapping['sourceEntity'] . '::' . $mapping['fieldName']] = $mapping;
             }
         }
     }
     return $relations;
 }
Exemplo n.º 9
0
 public function testGetIdsWithHidden()
 {
     $this->configManager->expects($this->once())->method('getIds')->with('testScope', DemoEntity::ENTITY_NAME, true)->will($this->returnValue(array($this->entityConfig->getId())));
     $this->assertEquals(array($this->entityConfig->getId()), $this->configProvider->getIds(DemoEntity::ENTITY_NAME, true));
 }