mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 13:33:48 +00:00
[wip] add actions to crud
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user