Skip to content

Commit

Permalink
Throw an error when the entity uses a custom on-the-fly type without …
Browse files Browse the repository at this point in the history
…defining its related template
  • Loading branch information
javiereguiluz committed Jul 14, 2015
1 parent a9203fa commit 149f806
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions DependencyInjection/EasyAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ private function filterRemovedActions(array $actionsConfiguration)
*/
private function processEntityTemplates(array $backendConfiguration)
{
$applicationTemplateDir = $this->kernelRootDir.'/Resources/views';
$applicationTemplatesDir = $this->kernelRootDir.'/Resources/views';
$bundleTemplatesDir = $this->kernelRootDir.'/../vendor/javiereguiluz/easyadmin-bundle/Resources/views';

$customDataTypesTemplates = $this->computeCustomDataTypesDefaultTemplates($backendConfiguration);

Expand All @@ -426,14 +427,16 @@ private function processEntityTemplates(array $backendConfiguration)
} elseif (isset($backendConfiguration['design']['templates'][$templateName])) {
$template = $backendConfiguration['design']['templates'][$templateName];
// 3rd level priority: app/Resources/views/easy_admin/<entityName>/<templateName>.html.twig
} elseif (file_exists($applicationTemplateDir.'/easy_admin/'.$entityName.'/'.$templateName.'.html.twig')) {
} elseif (file_exists($applicationTemplatesDir.'/easy_admin/'.$entityName.'/'.$templateName.'.html.twig')) {
$template = 'easy_admin/'.$entityName.'/'.$templateName.'.html.twig';
// 4th level priority: app/Resources/views/easy_admin/<templateName>.html.twig
} elseif (file_exists($applicationTemplateDir.'/easy_admin/'.$templateName.'.html.twig')) {
} elseif (file_exists($applicationTemplatesDir.'/easy_admin/'.$templateName.'.html.twig')) {
$template = 'easy_admin/'.$templateName.'.html.twig';
// 5th level priority: @EasyAdmin/default/<templateName>.html.twig
} else {
} elseif (file_exists($bundleTemplatesDir.'/default/'.$templateName.'.html.twig')) {
$template = $defaultTemplatePath;
} else {
throw new \RuntimeException(sprintf('The "%s" entity uses a custom data type called "%s" but its associated template is not defined in "app/resources/views/easy_admin/"', $entityName, str_replace('field_', '', $templateName)));
}

$entityConfiguration['templates'][$templateName] = $template;
Expand Down

0 comments on commit 149f806

Please sign in to comment.