From 0f255bb9d0f758142f0538d8f8aa5d29870b7bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Thu, 26 Jul 2018 16:44:56 +0200 Subject: [PATCH] :sparkles: feat(template) Add a method to alter template attributes This method allows to set some attributes as mandatory, readonly or hidden. It may be done in an other way later but this will allow to start testing it in public-forms plugin issue #5854 --- include/class_template.inc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/class_template.inc b/include/class_template.inc index f589585fd..7560af4e1 100644 --- a/include/class_template.inc +++ b/include/class_template.inc @@ -142,6 +142,35 @@ class template return $this->attributes; } + function alterAttributes($mandatories, $readonly, $hidden) + { + foreach ($mandatories as $class => $attrs) { + foreach ($attrs as $attr) { + if (!in_array($attr, $this->attributes[$class])) { + $this->attributes[$class][] = $attr; + } + $this->tabObject->by_object[$class]->attributesAccess[$attr]->setRequired(TRUE); + } + } + foreach ($readonly as $class => $attrs) { + foreach ($attrs as $attr) { + if (!in_array($attr, $this->attributes[$class])) { + $this->attributes[$class][] = $attr; + } + $this->tabObject->by_object[$class]->attributesAccess[$attr]->setDisabled(TRUE); + } + } + foreach ($hidden as $class => $attrs) { + foreach ($attrs as $attr) { + if (!in_array($attr, $this->attributes[$class])) { + $this->attributes[$class][] = $attr; + } + $this->tabObject->by_object[$class]->attributesAccess[$attr]->setDisabled(TRUE); + $this->tabObject->by_object[$class]->attributesAccess[$attr]->setVisible(FALSE); + } + } + } + function serialize() { $ret = array(); -- GitLab