CRUDlex\ControllerProvider::show PHP Method

show() public method

The controller for the "show" action.
public show ( Silex\Application $app, string $entity, string $id ) : Response
$app Silex\Application the Silex application
$entity string the current entity
$id string the instance id to show
return Symfony\Component\HttpFoundation\Response the HTTP response of this action or 404 on invalid input
    public function show(Application $app, $entity, $id)
    {
        $crudData = $app['crud']->getData($entity);
        $instance = $crudData->get($id);
        if (!$instance) {
            return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.instanceNotFound'));
        }
        $instance = [$instance];
        $crudData->fetchReferences($instance);
        $instance = $instance[0];
        $definition = $crudData->getDefinition();
        $childrenLabelFields = $definition->getChildrenLabelFields();
        $children = [];
        if (count($childrenLabelFields) > 0) {
            foreach ($definition->getChildren() as $child) {
                $childField = $child[1];
                $childEntity = $child[2];
                $childLabelField = array_key_exists($childEntity, $childrenLabelFields) ? $childrenLabelFields[$childEntity] : 'id';
                $childCrud = $app['crud']->getData($childEntity);
                $children[] = [$childCrud->getDefinition()->getLabel(), $childEntity, $childLabelField, $childCrud->listEntries([$childField => $instance->get('id')])];
            }
        }
        return $app['twig']->render($app['crud']->getTemplate($app, 'template', 'show', $entity), ['crudEntity' => $entity, 'entity' => $instance, 'children' => $children, 'layout' => $app['crud']->getTemplate($app, 'layout', 'show', $entity)]);
    }