[wip] add actions to crud

This commit is contained in:
2019-12-11 16:08:16 +01:00
parent d6354da24e
commit 199930d23a
16 changed files with 265 additions and 37 deletions

View File

@@ -41,10 +41,35 @@ class Resolver
*/
protected $propertyAccess;
function __construct(EntityManagerInterface $em)
/**
*
* @var array
*/
protected $crudConfig;
/**
* @deprecated
*/
const ROLE_VIEW = 'role.view';
/**
* @deprecated
*/
const ROLE_EDIT = 'role.edit';
/**
* The key to get the role necessary for the action
*/
const ROLE = 'role';
function __construct(EntityManagerInterface $em, array $crudConfig)
{
$this->em = $em;
foreach($crudConfig as $conf) {
$this->crudConfig[$conf['name']] = $conf;
}
$this->buildPropertyAccess();
}
@@ -69,13 +94,37 @@ class Resolver
return $this->propertyAccess->getValue($entity, $path);
}
public function getConfigValue($key, $crudName, $action = null)
{
$config = $this->crudConfig[$crudName];
switch ($key) {
case self::ROLE:
dump($config);
return $config['actions'][$action]['role'] ?? $this->buildDefaultRole($crudName, $action);
}
}
public function buildDefaultRole($crudName, $action)
{
if (empty($this->crudConfig[$crudName]['base_role'])) {
throw new \LogicException(sprintf("the base role is not defined. You must define "
. "on or override %s or %s methods", __METHOD__, "getRoleFor"));
}
return \strtoupper(
$this->crudConfig[$crudName]['base_role'].
'_'.
$action);
}
public function getTwigTemplate($entity, $path): string
{
list($focusEntity, $subPath) = $this->getFocusedEntity($entity, $path);
$classMetadata = $this->em->getClassMetadata(\get_class($focusEntity));
$type = $classMetadata->getTypeOfField($subPath);
dump($type);
switch ($type) {
default: