]> _ Git - cubist_cms-back.git/commitdiff
wait #6069 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Jun 2023 14:41:27 +0000 (16:41 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Jun 2023 14:41:27 +0000 (16:41 +0200)
src/app/Magic/Fields/SelectFromArray.php

index c2e55a299a504f4f28cb994c4f481b875d609b31..763a9a2845df0084473779a577169bb33f18f974 100644 (file)
@@ -24,11 +24,22 @@ class SelectFromArray extends Field
     protected $_ajax = true;
     protected $_allowsHTML = false;
 
+    protected $_excludedOptions = [];
+
     protected $_showSeletedOption = false;
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple, 'ajax' => $this->_ajax, 'allows_html' => $this->_allowsHTML, 'show_selected_option' => $this->_showSeletedOption]);
+        return array_merge(parent::getDefaultAttributes(), [
+            'options' => $this->getOptionsFiltered(),
+            'excluded_options' => $this->_excludedOptions,
+            'options_aliases' => $this->_options_aliases,
+            'allows_null' => $this->_allowNull,
+            'allows_multiple' => $this->_multiple,
+            'ajax' => $this->_ajax,
+            'allows_html' => $this->_allowsHTML,
+            'show_selected_option' => $this->_showSeletedOption
+        ]);
     }
 
     protected function _postSetAttributes()
@@ -68,6 +79,17 @@ class SelectFromArray extends Field
         return $this->_options;
     }
 
+    public function getOptionsFiltered()
+    {
+        $res = $this->getOptions();
+        foreach ($this->_excludedOptions as $excludedOption) {
+            if (isset($res[$excludedOption])) {
+                unset($res[$excludedOption]);
+            }
+        }
+        return $res;
+    }
+
     public function getColumnData()
     {
         $res = parent::getColumnData();