mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
[crud] clean and add documentation
This commit is contained in:
@@ -69,29 +69,6 @@ class Resolver
|
||||
foreach($crudConfig as $conf) {
|
||||
$this->crudConfig[$conf['name']] = $conf;
|
||||
}
|
||||
|
||||
$this->buildPropertyAccess();
|
||||
}
|
||||
|
||||
|
||||
private function buildPropertyAccess()
|
||||
{
|
||||
$this->propertyAccess = PropertyAccess::createPropertyAccessorBuilder()
|
||||
->enableExceptionOnInvalidIndex()
|
||||
->getPropertyAccessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data at given path.
|
||||
*
|
||||
* Path are given to
|
||||
*
|
||||
* @param object $entity
|
||||
* @param string $path
|
||||
*/
|
||||
public function getData($entity, $path)
|
||||
{
|
||||
return $this->propertyAccess->getValue($entity, $path);
|
||||
}
|
||||
|
||||
public function getConfigValue($key, $crudName, $action = null)
|
||||
@@ -116,43 +93,4 @@ class Resolver
|
||||
'_'.
|
||||
$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);
|
||||
|
||||
switch ($type) {
|
||||
|
||||
default:
|
||||
return '@ChillMain/CRUD/_inc/default.html.twig';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object on which the path apply
|
||||
*
|
||||
* This methods recursively parse the path and entity and return the entity
|
||||
* which will deliver the info, and the last path.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param string $path
|
||||
* @return array [$focusedEntity, $lastPath]
|
||||
*/
|
||||
private function getFocusedEntity($entity, $path)
|
||||
{
|
||||
if (\strpos($path, '.') === FALSE) {
|
||||
return [$entity, $path];
|
||||
}
|
||||
|
||||
$exploded = \explode('.', $path);
|
||||
|
||||
$subEntity = $this->propertyAccess
|
||||
->getValue($entity, $exploded[0]);
|
||||
|
||||
return $this->getFocusedEntity($subEntity,
|
||||
\implode('.', \array_slice($exploded, 1)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user