Cleanup config and fix rendering

This commit is contained in:
Tim
2020-07-27 01:02:18 +02:00
parent db970b4c69
commit 6c43ee8fd1
3 changed files with 45 additions and 41 deletions

View File

@ -2,9 +2,12 @@
namespace Ardent\ParameterBundle\Service;
use Ardent\ParameterBundle\DependencyInjection\Configuration;
use Ardent\ParameterBundle\Entity\Parameter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class ParameterService
{
@ -26,12 +29,12 @@ class ParameterService
{
$this->em = $em;
$this->parameter = $parameter;
$this->config = $config;
$this->config = $this->supplementConfig($config);
}
/**
* @param string $name
* @param bool $parse
* @param bool $parse
*
* @return string
*/
@ -80,6 +83,35 @@ class ParameterService
$this->em->flush();
}
/**
* Replaces the types in the config by their classes
*
* @param $config
* @return array
*/
private function supplementConfig($config)
{
foreach ($config as $groupName => &$group) {
foreach ($group as &$value) {
switch ($value['type']) {
default:
case Configuration::TYPE_TEXT:
$class = TextType::class;
break;
case Configuration::TYPE_NUMBER:
$class = NumberType::class;
break;
}
$value['name'] = sprintf('%s_%s', $groupName, $value['name']);
$value['type'] = $class;
unset($value);
}
unset($group);
}
return $config;
}
/**
* @return array
*/