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 all 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
24 changes: 12 additions & 12 deletions packages/admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ Usage example :
"pattern": "title",
"choice_obj_map": {
"value": "ident",
"label": "{{customLabelFunction}} - {{someAdditionalInfo }}"
"label": "{{ customLabelFunction }} - {{ someAdditionalInfo }}"
},
"selectize_templates": {
"item": "project/selectize/custom-item-template",
"option": "project/selectize/custom-option-template",
"controller": "project/selectize/custom-template"
"item": "{{> project/selectize/custom-item-template }}",
"option": "{{> project/selectize/custom-option-template }}",
"controller": "{{> project/selectize/custom-template }}"
},
"selectize_options": {
"plugins": {
Expand All @@ -339,26 +339,26 @@ Selectize templates examples :

<pre>
"selectize_templates": {
"item": "{{customLabelFunction}} - {{someAdditionalInfo }}",
"option": "{{customLabelFunction}} - {{someAdditionalInfo }}"
"item": "{{ customLabelFunction }} - {{ someAdditionalInfo }}",
"option": "{{ customLabelFunction }} - {{ someAdditionalInfo }}"
},

---

"selectize_templates": "{{customLabelFunction}} - {{someAdditionalInfo }}",
"selectize_templates": "{{ customLabelFunction }} - {{ someAdditionalInfo }}",

---

"selectize_templates": "project/selectize/custom-template",
"selectize_templates": "{{> project/selectize/custom-template }}",

---

"selectize_templates": {
"item": "project/selectize/custom-item-template",
"option": "project/selectize/custom-option-template",
"controller": "project/selectize/custom-template",
"item": "{{> project/selectize/custom-item-template }}",
"option": "{{> project/selectize/custom-option-template }}",
"controller": "{{> project/selectize/custom-template }}",
"data": {
"category": "{{selectedCategory}}"
"category": "{{ selectedCategory }}"
}
},
</pre>
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
7 changes: 7 additions & 0 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
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 @@ -4,9 +4,6 @@

// From Pimple
use Pimple\Container;
// From 'charcoal-view'
use Charcoal\View\ViewableInterface;
use Charcoal\View\ViewableTrait;
// From 'charcoal-translator'
use Charcoal\Translator\Translation;
// From 'charcoal-admin'
Expand All @@ -32,11 +29,8 @@
* }
* ```
*/
class MessageDisplay extends AbstractPropertyDisplay implements
ViewableInterface
class MessageDisplay extends AbstractPropertyDisplay
{
use ViewableTrait;

/**
* @var Translation|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

// from 'charcoal-admin'
use Charcoal\Admin\Property\AbstractPropertyDisplay;
// from 'charcoal-view'
use Charcoal\View\ViewableInterface;
use Charcoal\View\ViewableTrait;
// from 'pimple'
use Pimple\Container;
use UnexpectedValueException;
Expand All @@ -16,10 +13,8 @@
*
* The default display for most properties; only output {@see AbstractProperty::displayVal()}.
*/
class StatusDisplay extends AbstractPropertyDisplay implements ViewableInterface
class StatusDisplay extends AbstractPropertyDisplay
{
use ViewableTrait;

public const STATE_PRIMARY = 'primary';
public const STATE_SUCCESS = 'success';
public const STATE_INFO = 'info';
Expand Down Expand Up @@ -68,9 +63,6 @@ class StatusDisplay extends AbstractPropertyDisplay implements ViewableInterface
protected function setDependencies(Container $container)
{
parent::setDependencies($container);

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

/**
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
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 @@ -2,51 +2,34 @@

namespace Charcoal\Admin\ServiceProvider;

// From Pimple
use Charcoal\Admin\AssetsConfig;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Assetic\Asset\AssetReference;
use Charcoal\Attachment\Object\File;
use Charcoal\Factory\GenericResolver;
// from 'kriswallsmith/assetic'
use Assetic\AssetManager;
// From PSR-7
use Psr\Http\Message\UriInterface;
// From Slim
use Slim\Http\Uri;
// From Mustache
use Mustache_LambdaHelper as LambdaHelper;
// From 'charcoal-config'
use Charcoal\Admin\AssetsConfig;
use Charcoal\Admin\Config as AdminConfig;
use Charcoal\Admin\Property\PropertyDisplayInterface;
use Charcoal\Admin\Property\PropertyInputInterface;
use Charcoal\Admin\Service\SelectizeRenderer;
use Charcoal\Admin\Ui\SecondaryMenu\GenericSecondaryMenuGroup;
use Charcoal\Admin\Ui\SecondaryMenu\SecondaryMenuGroupInterface;
use Charcoal\Admin\User;
use Charcoal\Admin\User\AuthToken;
use Charcoal\Attachment\Object\File;
use Charcoal\Config\ConfigInterface;
use Charcoal\Config\GenericConfig as Config;
// From 'charcoal-factory'
use Charcoal\Email\ServiceProvider\EmailServiceProvider;
use Charcoal\Factory\FactoryInterface;
// From 'charcoal-core'
use Charcoal\Factory\GenericFactory as Factory;
use Charcoal\Factory\GenericResolver;
use Charcoal\Model\Service\MetadataConfig;
// From 'charcoal-ui'
use Charcoal\Ui\ServiceProvider\UiServiceProvider;
// From 'charcoal-email'
use Charcoal\Email\ServiceProvider\EmailServiceProvider;
// From 'charcoal-factory'
use Charcoal\Factory\GenericFactory as Factory;
// From 'charcoal-user'
use Charcoal\User\Authenticator;
use Charcoal\User\Authorizer;
// From 'charcoal-view'
use Charcoal\View\EngineInterface;
use Charcoal\View\GenericView;
use Charcoal\View\ViewConfig;
use Charcoal\View\ViewInterface;
// From 'charcoal-admin'
use Charcoal\Admin\Config as AdminConfig;
use Charcoal\Admin\Property\PropertyInputInterface;
use Charcoal\Admin\Property\PropertyDisplayInterface;
use Charcoal\Admin\Service\SelectizeRenderer;
use Charcoal\Admin\Ui\SecondaryMenu\GenericSecondaryMenuGroup;
use Charcoal\Admin\Ui\SecondaryMenu\SecondaryMenuGroupInterface;
use Charcoal\Admin\User;
use Charcoal\Admin\User\AuthToken;
use Mustache_LambdaHelper as LambdaHelper;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Psr\Http\Message\UriInterface;
use Slim\Http\Uri;

/**
* Charcoal Administration Service Provider
Expand Down Expand Up @@ -174,25 +157,12 @@ protected function registerAdminServices(Container $container)
};
}

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

/**
* Extend view/config.
*
* @param ConfigInterface $viewConfig The view config instance.
* @param Container $container A container instance.
* @return ViewInterface
* @return ViewConfig
*/
$container->extend('view/config', function (ViewConfig $viewConfig, Container $container): ViewConfig {
$adminConfig = $container['admin/config'];
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);
} 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 @@ -9,6 +9,8 @@
use Charcoal\Factory\FactoryInterface;
// From 'charcoal-ui'
use Charcoal\Ui\FormGroup\AbstractFormGroup;
// From 'charcoal-translator'
use Charcoal\Translator\Translation;
// From 'charcoal-admin'
use Charcoal\Admin\Ui\NestedWidgetContainerInterface;
use Charcoal\Admin\Ui\NestedWidgetContainerTrait;
Expand Down Expand Up @@ -114,19 +116,26 @@ public function setWidgetId($widgetId)
}

/**
* @return Translation|string|null
* @param mixed $description The description attribute.
* @return FormGroupWidget Chainable
*/
public function description()
public function setDescription($description)
{
return $this->renderTemplate((string)parent::description());
$description = $this->translator()->translate($description);
$description = $this->renderTemplate($description);
return parent::setDescription($description);
}


/**
* @return Translation|string|null
* @param mixed $notes The notes attribute.
* @return FormGroupWidget Chainable
*/
public function notes()
public function setNotes($notes)
{
return $this->renderTemplate((string)parent::notes());
$notes = $this->translator()->translate($notes);
$notes = $this->renderTemplate($notes);
return parent::setNotes($notes);
}

/**
Expand Down
Loading