Rajout de la gestion des formulaires dans \Custom
[zf2.biz/application_blanche.git] / vendor / zf2biz / Custom / Form / AbstractForm.php
diff --git a/vendor/zf2biz/Custom/Form/AbstractForm.php b/vendor/zf2biz/Custom/Form/AbstractForm.php
new file mode 100644 (file)
index 0000000..f7f5249
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+namespace Custom\Form;
+
+use Zend\Form\Form;
+
+use Zend\I18n\Translator\TranslatorAwareInterface;
+use Zend\I18n\Translator\Translator;
+
+
+class AbstractForm extends Form implements TranslatorAwareInterface
+{
+
+    private $_translator = null;
+    private $_textDomain = 'default';
+    private $_translator_enabled = false; 
+
+
+    abstract public function initialize();
+
+
+
+
+    public function translate($k)
+    {
+        if ($this->_translator && $this->_translator_enabled) {
+            return $this->_translator->translate($k, $this->_textDomain);
+        }
+        return $k;
+    }
+
+
+
+
+    protected function addElement($name, $type='text', $label=null, $attributes=array(), $options=array())
+    {
+        if ($type) {
+            $attributes['type' = $type
+        }
+        if ($label) {
+            $options['label'] = $label;
+        }
+        $params = array('name' => $name);
+        if ($attributes) {
+            $params['attributes'] = $attributes;
+        }
+        if ($options) {
+            $params['options'] = $options;
+        }
+        $this->add($params);
+    }
+
+
+
+
+    public function setTranslator(Translator $translator = null, $textDomain = null)
+    {
+        $this->_translator = $translator;
+       $this->_textDomain = $textDomain;
+    }
+
+    public function getTranslator()
+    {
+        return $this->_translator;
+    }
+
+    public function hasTranslator()
+    {
+        return $this->_translator !== null;
+    }
+
+    public function setTranslatorEnabled($enabled = true)
+    {
+        $this->_translator_enabled = $enabed;
+    }
+
+    public function isTranslatorEnabled()
+    {
+        return $this->_translator_enabled;
+    }
+
+    public function setTranslatorTextDomain($textDomain = 'default')
+    {
+       $this->_textDomain = $textDomain;
+    }
+
+    public function getTranslatorTextDomain()
+    {
+        return $this->_textDomain;
+    }
+
+
+    protected function setMethod($method='post')
+    {
+        $this->setAttribute('method', $method);
+    }
+
+}