diff --git a/config/form-templates.php b/config/form-templates.php index 3b97cf0..cda88ef 100644 --- a/config/form-templates.php +++ b/config/form-templates.php @@ -7,10 +7,12 @@ return [ 'button' => '', 'checkbox' => '', - 'input' => '', + 'error' => '
{{content}}
', + 'input' => '', 'inputContainer' => '
{{content}}
', + 'inputContainerError' => '
{{content}}
{{error}}', 'label' => '', - 'textarea' => '', - 'select' => '', - 'selectMultiple' => '', + 'textarea' => '', + 'select' => '', + 'selectMultiple' => '', ]; diff --git a/config/html-templates.php b/config/html-templates.php new file mode 100644 index 0000000..45b368d --- /dev/null +++ b/config/html-templates.php @@ -0,0 +1,6 @@ + '{{content}}', +]; diff --git a/config/paginator-templates.php b/config/paginator-templates.php index bb9ceb8..38ed095 100644 --- a/config/paginator-templates.php +++ b/config/paginator-templates.php @@ -5,9 +5,9 @@ * Custom templates for pagination elements. */ return [ - 'nextActive' => '', + 'nextActive' => '
  • ', 'nextDisabled' => '', - 'prevActive' => '', + 'prevActive' => '
  • ', 'prevDisabled' => '', 'counterRange' => '{{start}} - {{end}} of {{count}}', 'counterPages' => '{{page}} of {{pages}}', @@ -16,9 +16,9 @@ 'number' => '
  • {{text}}
  • ', 'current' => '
  • {{text}}
  • ', 'ellipsis' => '
  • ', - 'sort' => '{{text}}', - 'sortAsc' => '{{text}}', - 'sortDesc' => '{{text}}', + 'sort' => '{{text}}', + 'sortAsc' => "{{text}}", + 'sortDesc' => "{{text}}", 'sortAscLocked' => '{{text}}', 'sortDescLocked' => '{{text}}', ]; diff --git a/src/View/AppView.php b/src/View/AppView.php index 07a8ae0..0857f8e 100644 --- a/src/View/AppView.php +++ b/src/View/AppView.php @@ -39,5 +39,6 @@ public function initialize(): void { $this->loadHelper('Paginator', ['templates' => 'paginator-templates']); $this->loadHelper('Form', ['templates' => 'form-templates']); + $this->loadHelper('Html', ['templates' => 'html-templates']); } } diff --git a/templates/element/flash/error.php b/templates/element/flash/error.php index 2ebf235..cd06b50 100644 --- a/templates/element/flash/error.php +++ b/templates/element/flash/error.php @@ -8,4 +8,4 @@ $message = h($message); } ?> -
    +
    diff --git a/templates/element/flash/info.php b/templates/element/flash/info.php index e25b730..6bb1fb4 100644 --- a/templates/element/flash/info.php +++ b/templates/element/flash/info.php @@ -8,4 +8,4 @@ $message = h($message); } ?> -
    +
    diff --git a/templates/element/flash/success.php b/templates/element/flash/success.php index 73eaac4..bf4aa36 100644 --- a/templates/element/flash/success.php +++ b/templates/element/flash/success.php @@ -8,4 +8,4 @@ $message = h($message); } ?> -
    +
    diff --git a/templates/element/flash/warning.php b/templates/element/flash/warning.php index 605537c..0c42990 100644 --- a/templates/element/flash/warning.php +++ b/templates/element/flash/warning.php @@ -8,4 +8,4 @@ $message = h($message); } ?> -
    +
    diff --git a/templates/layout/default.php b/templates/layout/default.php index 2f26330..2374c0a 100644 --- a/templates/layout/default.php +++ b/templates/layout/default.php @@ -41,11 +41,11 @@
    - Documentation - API + Html->link('Documentation', 'https://book.cakephp.org/5/', ['target' => '_blank', 'rel' => 'noopener']) ?> + Html->link('Documentation', 'https://api.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?>
    -
    +
    Flash->render() ?> fetch('content') ?> diff --git a/templates/plugin/Bake/Template/edit.twig b/templates/plugin/Bake/Template/edit.twig new file mode 100644 index 0000000..90fed4e --- /dev/null +++ b/templates/plugin/Bake/Template/edit.twig @@ -0,0 +1,35 @@ +{# +/** + * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) + * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) + * + * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice. + * + * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) + * @link https://cakephp.org CakePHP(tm) Project + * @since 2.0.0 + * @license https://www.opensource.org/licenses/mit-license.php MIT License + */ +#} + +{{ element('Bake.form') }} \ No newline at end of file diff --git a/templates/plugin/Bake/Template/index.twig b/templates/plugin/Bake/Template/index.twig index 2006b95..55ffedb 100644 --- a/templates/plugin/Bake/Template/index.twig +++ b/templates/plugin/Bake/Template/index.twig @@ -23,11 +23,7 @@ {% set fields = Bake.filterFields(fields, schema, modelObject, indexColumns, ['binary', 'text']) %}

    - Html->link( - __('New {{ singularHumanName }}'), - ['action' => 'add'], - ['class' => 'bg-red-700 hover:bg-red-900 text-white font-bold py-2 px-4 rounded'] - ) ?> + Html->link( __('New {{ singularHumanName }}'), ['action' => 'add']) ?>
    {% set done = [] %}
    @@ -42,7 +38,7 @@ - + {% for field in fields %} {% set isKey = false %} {% if associations.BelongsTo is defined %} diff --git a/templates/plugin/Bake/Template/view.twig b/templates/plugin/Bake/Template/view.twig new file mode 100644 index 0000000..ccd34b3 --- /dev/null +++ b/templates/plugin/Bake/Template/view.twig @@ -0,0 +1,158 @@ +{# +/** + * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) + * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) + * + * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice. + * + * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) + * @link https://cakephp.org CakePHP(tm) Project + * @since 2.0.0 + * @license https://www.opensource.org/licenses/mit-license.php MIT License + */ +#} + +{% set associations = {'BelongsTo': [], 'HasOne': [], 'HasMany': [], 'BelongsToMany': []}|merge(associations) %} +{% set fieldsData = Bake.getViewFieldsData(fields, schema, associations) %} +{% set associationFields = fieldsData.associationFields %} +{% set groupedFields = fieldsData.groupedFields %} +{% set pK = '$' ~ singularVar ~ '->' ~ primaryKey[0] %} +
    + +
    +
    +

    {{ displayField }}) ?>

    + +{% if groupedFields['string'] %} +{% for field in groupedFields['string'] %} +{% if associationFields[field] is defined %} +{% set details = associationFields[field] %} + + + + +{% else %} + + + + +{% endif %} +{% endfor %} +{% endif %} +{% if associations.HasOne %} +{% for alias, details in associations.HasOne %} + + + + +{% endfor %} +{% endif %} +{% if groupedFields.number %} +{% for field in groupedFields.number %} + + +{% set columnData = Bake.columnData(field, schema) %} +{% if columnData.null %} + +{% else %} + +{% endif %} + +{% endfor %} +{% endif %} +{% if groupedFields.enum %} +{% for field in groupedFields.enum %} + + +{% set columnData = Bake.columnData(field, schema) %} +{% set supportsLabel = Bake.enumSupportsLabel(field, schema) %} +{% if columnData.null %} + +{% else %} + +{% endif %} + +{% endfor %} +{% endif %} +{% if groupedFields.date %} +{% for field in groupedFields.date %} + + + + +{% endfor %} +{% endif %} +{% if groupedFields.boolean %} +{% for field in groupedFields.boolean %} + + + + +{% endfor %} +{% endif %} +
    hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?>
    {{ field }}) ?>
    hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?>
    {{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?>Number->format(${{ singularVar }}->{{ field }}) ?>
    {{ field }} === null ? '' : h(${{ singularVar }}->{{ field }}->{% if supportsLabel %}label(){% else %}value{% endif %}) ?>{{ field }}->{% if supportsLabel %}label(){% else %}value{% endif %}) ?>
    {{ field }}) ?>
    {{ field }} ? __('Yes') : __('No'); ?>
    +{% if groupedFields.text %} +{% for field in groupedFields.text %} +
    + +
    + Text->autoParagraph(h(${{ singularVar }}->{{ field }})); ?> +
    +
    +{% endfor %} +{% endif %} +{% set relations = associations.BelongsToMany|merge(associations.HasMany) %} +{% for alias, details in relations %} +{% set otherSingularVar = alias|singularize|variable %} +{% set otherPluralHumanName = details.controller|underscore|humanize %} +
    +

    + {{ details.property }})) : ?> + + +{% for field in details.fields %} + +{% endfor %} + + + {{ details.property }} as ${{ otherSingularVar }}) : ?> + +{% for field in details.fields %} + +{% endfor %} +{% set otherPk = '$' ~ otherSingularVar ~ '->' ~ details.primaryKey[0] %} + + + +
    {{ field }}) ?> + Html->link(__('View'), ['controller' => '{{ details.controller }}', 'action' => 'view', {{ otherPk|raw }}]) ?> + Html->link(__('Edit'), ['controller' => '{{ details.controller }}', 'action' => 'edit', {{ otherPk|raw }}]) ?> + Form->postLink( + __('Delete'), + ['controller' => '{{ details.controller }}', 'action' => 'delete', {{ otherPk|raw }}], + [ + 'method' => 'delete', + 'confirm' => __('Are you sure you want to delete # {0}?', {{ otherPk|raw }}), + ] + ) ?> +
    + +
    +{% endfor %} +
    +
    +
    \ No newline at end of file diff --git a/templates/plugin/Bake/element/form.twig b/templates/plugin/Bake/element/form.twig index 8f0c46b..cfbca2c 100644 --- a/templates/plugin/Bake/element/form.twig +++ b/templates/plugin/Bake/element/form.twig @@ -15,20 +15,18 @@ #} {% set fields = Bake.filterFields(fields, schema, modelObject) %}
    -