summaryrefslogtreecommitdiff
path: root/fai_gestion/plugins/CustomTheme
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2018-07-23 21:06:10 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2018-07-23 21:06:10 +0200
commit78043e3cccdf88981e79f14f3249c43a41211df7 (patch)
tree84a9528256608690dec9f06ec106b659f5b4578f /fai_gestion/plugins/CustomTheme
parent4e2624a23f056b985a7613fe6c648e9abb20e261 (diff)
downloadchd_gestion-78043e3cccdf88981e79f14f3249c43a41211df7.zip
chd_gestion-78043e3cccdf88981e79f14f3249c43a41211df7.tar.gz
chd_gestion-78043e3cccdf88981e79f14f3249c43a41211df7.tar.bz2
bake : action view/related items, limit to available actions.cake36
Bonus : don't display foreign key (if display here == view $id)
Diffstat (limited to 'fai_gestion/plugins/CustomTheme')
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig8
-rw-r--r--fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php11
2 files changed, 10 insertions, 9 deletions
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
index 0b2dd28..17e7be0 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
@@ -149,7 +149,7 @@
{% for alias, details in relations %}
{% set otherSingularVar = alias|variable %}
{% set otherPluralHumanName = details.controller|underscore|humanize %}
-{% set fields = BakeExtra.filterFieldsOther(details.fields, details.controller) %}
+{% set fields = BakeExtra.filterFieldsOther(details.fields, details.controller, details.foreignKey) %}
<div class="related">
<h4><?= __('Related {{ otherPluralHumanName }}') ?></h4>
<?php if (!empty(${{ singularVar }}->{{ details.property }})): ?>
@@ -167,9 +167,15 @@
{% endfor %}
{% set otherPk = '$' ~ otherSingularVar ~ '->' ~ details.primaryKey[0] %}
<td class="actions">
+{% if BakeExtra.hasAction('view', details.controller) %}
<?= $this->Html->link(__('View'), ['controller' => '{{ details.controller }}', 'action' => 'view', {{ otherPk|raw }}]) ?>
+{% endif %}
+{% if BakeExtra.hasAction('edit', details.controller) %}
<?= $this->Html->link(__('Edit'), ['controller' => '{{ details.controller }}', 'action' => 'edit', {{ otherPk|raw }}]) ?>
+{% endif %}
+{% if BakeExtra.hasAction('delete', details.controller) %}
<?= $this->Form->postLink(__('Delete'), ['controller' => '{{ details.controller }}', 'action' => 'delete', {{ otherPk|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ otherPk|raw }})]) ?>
+{% endif %}
</td>
</tr>
<?php endforeach; ?>
diff --git a/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php b/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
index a495973..d483d61 100644
--- a/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
+++ b/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
@@ -105,23 +105,18 @@ class BakeExtraHelper extends Helper
return $coll->take($takeFields)->toArray();
}
- public function filterFieldsOther($fields, $controllerName) {
-
+ public function filterFieldsOther($fields, $controllerName, $foreignKey) {
$takeFields = Hash::get($this->_config, "taskParams.$controllerName.index-columns");
if ( $takeFields === NULL )
$takeFields = Hash::get($this->_config, "taskParams.default.index-columns");
- //$filterTypes = ['binary']; // TODO
- $rejectFields = ['id'];
+ $rejectFields = ['id', $foreignKey ];
- $coll = collection($fields);
- $coll = $coll->reject(function ($field, $key) use ($rejectFields) {
+ $coll = collection($fields)->reject(function ($field, $key) use ($rejectFields) {
return in_array($field, $rejectFields);
});
-
return $coll->take($takeFields)->toArray();
}
-
public function getTitleOpts($controllerName) {
if ( ! is_string($controllerName) ) return FALSE;
return Hash::get($this->_config, "templateExtra.$controllerName.title");