Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve view engines and their integration in the Admin #70

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function results()
protected function setDependencies(Container $container)
{
parent::setDependencies($container);
$this->setEmailFactory($container['admin/email/factory']);
$this->setEmailFactory($container['email/factory']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function run(RequestInterface $request, ResponseInterface $response)
$widget->setData($widgetOptions);
}

$widgetHtml = $widget->renderTemplate($widget->template());
$widgetHtml = $widget->render($widget->template());
$sharedJs = $widget->renderTemplate('{{&jsRequirements}}');
$uniqueJs = $widget->renderTemplate('{{&js}}');
$widgetId = $widget->widgetId();
Expand Down Expand Up @@ -319,7 +319,7 @@ protected function setDependencies(Container $container)
parent::setdependencies($container);

$this->setWidgetFactory($container['widget/factory']);
$this->setWidgetView($container['admin/view']);
$this->setWidgetView($container['view']);
}


Expand Down
17 changes: 12 additions & 5 deletions packages/admin/src/Charcoal/Admin/AdminModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Charcoal\App\Module\AbstractModule;
// From 'charcoal-admin'
use Charcoal\Admin\ServiceProvider\AdminServiceProvider;
use Charcoal\View\ViewAggregator;

/**
* Charcoal Administration Module
Expand Down Expand Up @@ -46,6 +47,12 @@ public function setUp()
}
$container->register(new AdminServiceProvider());

/* Last resort solution
if ($container['view'] instanceof ViewAggregator) {
$container['view']->using('mustache');
}
*/

$module = $this;
$container['charcoal/admin/module'] = function () use ($module) {
return $module;
Expand Down Expand Up @@ -105,7 +112,7 @@ public function setupHandlers(
$container->extend('notFoundHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
$adminView = $container['view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -129,7 +136,7 @@ public function setupHandlers(
$container->extend('notAllowedHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
$adminView = $container['view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -153,7 +160,7 @@ public function setupHandlers(
$container->extend('phpErrorHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
$adminView = $container['view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -177,7 +184,7 @@ public function setupHandlers(
$container->extend('errorHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
$adminView = $container['view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -203,7 +210,7 @@ public function setupHandlers(
$container->extend('maintenanceHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
$adminView = $container['view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Charcoal/Admin/AdminWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ protected function setDependencies(Container $container)

// Satisfies AdminWidget dependencies
$this->setModelFactory($container['model/factory']);
$this->setView($container['admin/view']);
$this->setView($container['view']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function title()
}

if ($this->isObjRenderable($obj)) {
$this->title = $obj->render((string)$objLabel, $obj);
$this->title = $obj->renderTemplate((string)$objLabel, $obj);
} else {
$this->title = (string)$objLabel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ protected function setDependencies(Container $container)
$this->setTranslator($container['translator']);

// Fulfills the ViewableTrait dependencies
$this->setView($container['admin/view']);
$this->setView($container['view']);

// Fulfills the DebugAwareTrait dependencies
$this->setDebug($container['debug']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function displayVal()
$display->setData($propertyData);
$display->setPropertyVal($propertyValue);

return $this->view()->renderTemplate($displayType, $display);
return $this->view()->render($displayType, $display);
}

/**
Expand Down
26 changes: 0 additions & 26 deletions packages/admin/src/Charcoal/Admin/Route/TemplateRoute.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function setDependencies(Container $container)
parent::setDependencies($container);
$this->setNotificationFactory($container['model/factory']);
$this->setRevisionFactory($container['model/factory']);
$this->emailFactory = $container['admin/email/factory'];
$this->emailFactory = $container['email/factory'];
$this->userFactory = $container['model/factory'];
$this->objectFactory = $container['model/factory'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ public function renderTemplate($templateIdent, $context, $controllerIdent = null
$template = $context;
}

return $this->view->render($templateIdent, $template);
return $this->view->renderTemplate($templateIdent, $template);
mcaskill marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use Charcoal\View\ViewInterface;
// From 'charcoal-admin'
use Charcoal\Admin\Config as AdminConfig;
use Charcoal\Admin\Route\TemplateRoute as AdminTemplateRoute;
use Charcoal\Admin\Property\PropertyInputInterface;
use Charcoal\Admin\Property\PropertyDisplayInterface;
use Charcoal\Admin\Service\SelectizeRenderer;
Expand Down Expand Up @@ -84,8 +83,6 @@ public function register(Container $container)
$this->registerFactoryServices($container);
$this->registerElfinderServices($container);
$this->registerSelectizeServices($container);
$this->registerModelDependencies($container);
$this->registerRouteServices($container);
$this->registerMetadataExtensions($container);
$this->registerAuthExtensions($container);
$this->registerViewExtensions($container);
Expand Down Expand Up @@ -181,42 +178,6 @@ protected function registerAdminServices(Container $container)
};
}

/**
* @param Container $container Pimple DI Container.
* @return FactoryInterface
*/
$container['admin/email/factory'] = function (Container $container): FactoryInterface {
return new GenericFactory([
'map' => [
'email' => Email::class
],
'base_class' => EmailInterface::class,
'default_class' => Email::class,
'arguments' => [[
'logger' => $container['logger'],
'config' => $container['email/config'],
'view' => $container['admin/view'],
'template_factory' => $container['template/factory'],
'queue_item_factory' => $container['model/factory'],
'log_factory' => $container['model/factory'],
'tracker' => $container['email/tracker']
]]
]);
};

/**
* The admin view instance.
*
* @param GenericView $view The view instance.
* @param Container $container A container instance.
* @return ViewInterface
*/
$container['admin/view'] = function (Container $container): ViewInterface {
return new GenericView([
'engine' => $container['view/engine/mustache']
]);
};

/**
* Extend view/config.
*
Expand All @@ -233,31 +194,6 @@ protected function registerAdminServices(Container $container)
});
}

/**
* @param Container $container A Pimple DI container.
* @return void
*/
protected function registerModelDependencies(Container $container)
{
/**
* @param Container $container A Pimple DI container.
* @return array The model dependencies array.
*/
$container->extend('model/dependencies', function (array $modelDependencies, Container $container) {
$modelDependencies['view'] = $container['admin/view'];
return $modelDependencies;
});
}

/**
* @param Container $container A service container.
* @return void
*/
protected function registerRouteServices(Container $container)
{
$container['route/controller/template/class'] = AdminTemplateRoute::class;
}

/**
* Registers metadata extensions.
*
Expand Down Expand Up @@ -523,7 +459,7 @@ protected function registerSelectizeServices(Container $container)
'logger' => $container['logger'],
'translator' => $container['translator'],
'template_factory' => $container['template/factory'],
'view' => $container['admin/view']
'view' => $container['view']
]);
};
}
Expand Down Expand Up @@ -594,7 +530,7 @@ protected function registerFactoryServices(Container $container)
'arguments' => [[
'container' => $container,
'logger' => $container['logger'],
'view' => $container['admin/view'],
'view' => $container['view'],
'layout_builder' => $container['layout/builder']
]],
'resolver_options' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function title()
}

if ($listIdent && $hasView) {
$listIdent = $model->render($listIdent);
$listIdent = $model->renderTemplate($listIdent);
}

if (isset($adminMetadata['lists'][$listIdent]['label'])) {
Expand All @@ -191,7 +191,7 @@ public function title()
}

if ($hasView) {
$this->title = $model->render((string)$objLabel, $model);
$this->title = $model->renderTemplate((string)$objLabel);
} else {
$this->title = (string)$objLabel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function renderTitle($title)
{
$obj = $this->obj();
if ($this->isObjRenderable($obj)) {
return $obj->render((string)$title, $obj);
return $obj->renderTemplate((string)$title, $obj);
} else {
return (string)$title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function parseActionItem($action, $ident, $renderer = false)
}

if (isset($action['extraTemplate'])) {
$action['extraTemplate'] = $this->render($action['extraTemplate']);
$action['extraTemplate'] = $this->renderTemplate($action['extraTemplate']);
}

if (isset($action['dataAttributes']) && is_array($action['dataAttributes'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public function objectRows()
$displayType = $this->display->displayType();
$this->display->setPropertyVal($object->propertyValue($propertyIdent));

$propertyValue = $this->view()->renderTemplate($displayType, $this->display);
$propertyValue = $this->view()->render($displayType, $this->display);

$cell = $this->parsePropertyCell($object, $property, $propertyValue);
$objectProperties[] = $cell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected function renderData($data)

// Make sure there's an "out"
if ($obj instanceof ViewableInterface && ($obj->view() instanceof ViewInterface)) {
$data = $obj->view()->render($data, $obj->viewController());
$data = $obj->view()->renderTemplate($data, $obj->viewController());
} else {
$data = preg_replace_callback('~\{\{\s*(.*?)\s*\}\}~i', [ $this, 'parseDataToken' ], $data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function dataFromObject()
}

if ($collectionIdent && $this->isObjRenderable($proto)) {
$collectionIdent = $proto->render($collectionIdent);
$collectionIdent = $proto->renderTemplate($collectionIdent);
}

if (!$collectionIdent) {
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Charcoal/Admin/Widget/DocWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function setNextUrl($url)

$obj = $this->obj();
if ($obj && $this->isObjRenderable($obj)) {
$url = $obj->render($url);
$url = $obj->renderTemplate($url);
}

$this->nextUrl = $url;
Expand Down Expand Up @@ -572,7 +572,7 @@ protected function dataFromObject()
}

if ($formIdent && $this->isObjRenderable($obj)) {
$formIdent = $obj->render($formIdent);
$formIdent = $obj->renderTemplate($formIdent);
}

if (isset($adminMetadata['forms'][$formIdent])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,16 @@ public function setWidgetId($widgetId)
/**
* @return Translation|string|null
*/
public function description()
public function setDescription($description)
{
return $this->renderTemplate((string)parent::description());
parent::setDescription($this->renderTemplate($description));
mcaskill marked this conversation as resolved.
Show resolved Hide resolved
return $this;
}

/**
* @return Translation|string|null
*/
public function notes()
public function setNotes($notes)
{
return $this->renderTemplate((string)parent::notes());
parent::setNotes($this->renderTemplate($notes));
return $this;
}

/**
Expand Down Expand Up @@ -161,7 +160,7 @@ protected function setDependencies(Container $container)
$this->setWidgetFactory($container['widget/factory']);

// Satisfies Charcoal\View\ViewableInterface dependencies
$this->setView($container['admin/view']);
$this->setView($container['view']);
}

/**
Expand Down
Loading