From 155839f9cc49d76de5541c0f2e01c6bf1ea4a8bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Wed, 26 Sep 2018 14:45:41 +0200
Subject: [PATCH] :ambulance: fix(core) Fix %askme% support for
 BooleanAttribute

issue #5897
---
 .../attributes/class_BooleanAttribute.inc       | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/include/simpleplugin/attributes/class_BooleanAttribute.inc b/include/simpleplugin/attributes/class_BooleanAttribute.inc
index c1b1bba5a..69f258fcf 100644
--- a/include/simpleplugin/attributes/class_BooleanAttribute.inc
+++ b/include/simpleplugin/attributes/class_BooleanAttribute.inc
@@ -50,15 +50,24 @@ class BooleanAttribute extends Attribute
     $this->templatable = $bool;
   }
 
+  protected function isTemplatable()
+  {
+    /* Allow to set to %askme% if we are not (de)activating other fields */
+    return (!$this->submitForm && empty($this->managedAttributes) && $this->templatable);
+  }
+
   function inputValue ($value)
   {
+    if ($this->isTemplate() && $this->isTemplatable() && ($value == '%askme%')) {
+      return $value;
+    }
     return ($value == $this->trueValue);
   }
 
   function loadPostValue ()
   {
     if ($this->isVisible()) {
-      if ($this->isTemplate() && !$this->submitForm && empty($this->managedAttributes)) {
+      if ($this->isTemplate() && $this->isTemplatable()) {
         if (!isset($_POST[$this->getHtmlId()])) {
           $this->setPostValue(FALSE);
         } elseif ($_POST[$this->getHtmlId()] == '%askme%') {
@@ -74,7 +83,7 @@ class BooleanAttribute extends Attribute
 
   function computeLdapValue ()
   {
-    if ($this->isTemplate() && ($this->value == '%askme%')) {
+    if ($this->isTemplate() && $this->isTemplatable() && ($this->value == '%askme%')) {
       return $this->value;
     } else {
       return ($this->value ? $this->trueValue : $this->falseValue);
@@ -98,9 +107,7 @@ class BooleanAttribute extends Attribute
 
   function renderTemplateInput ()
   {
-    if (!$this->submitForm && empty($this->managedAttributes) && $this->templatable) {
-      /* Allow to set to %askme% if we are not (de)activating other fields */
-
+    if ($this->isTemplatable()) {
       $id = $this->getHtmlId();
       if ($this->getValue() == '%askme%') {
         $selected = '%askme%';
-- 
GitLab