..
상속: extends Zend\Form\Form
예제 #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetValue()
 {
     $this->assertNull($this->object->getValue('undefined'));
     $element = new Element\Text('text');
     $element->setValue('string');
     $this->object->add($element);
     $this->assertEquals('string', $this->object->getValue('text'));
 }
예제 #2
0
 /**
  * Load mixed prevalue editor
  *
  * @return string
  */
 public function load()
 {
     $config = $this->getConfig();
     $listDir = $this->getDatatype()->getDatatypesList();
     $options = array();
     foreach ($listDir as $dir) {
         $options[$dir] = $dir;
     }
     $datatypes = empty($config['datatypes']) ? array() : $config['datatypes'];
     foreach ($datatypes as $datatypeId => $datatypeConfig) {
         //Get datatypes
         $object = $this->loadDatatype($datatypeConfig['name']);
         //Force configuration
         $object->getPrevalueEditor()->setConfig(empty($datatypeConfig['config']) ? null : serialize($datatypeConfig['config']));
         //Initiliaze prefix
         $prefix = 'datatypes[' . $datatypeId . ']';
         //Create form
         $fieldset = new Fieldset();
         $hidden = new Element\Hidden();
         $hidden->setName($prefix . '[name]');
         $hidden->setValue($datatypeConfig['name']);
         $fieldset->add($hidden);
         $label = new Element\Text();
         $label->setName($prefix . '[label]');
         $label->setAttribute('class', 'form-control');
         $label->setLabel('Label');
         $label->setAttribute('id', 'label' . $datatypeId);
         $label->setValue(empty($datatypeConfig['label']) ? '' : $datatypeConfig['label']);
         $fieldset->add($label);
         AbstractForm::addContent($fieldset, $object->getPrevalueEditor()->load(), $prefix);
         $datatypes[$datatypeId]['fieldset'] = $fieldset;
     }
     $data = array();
     $data['datatypes'] = $datatypes;
     $data['modelOptions'] = $options;
     return $this->addPath(__DIR__)->render('mixed-prevalue.phtml', $data);
 }
예제 #3
0
파일: Document.php 프로젝트: gotcms/gotcms
 /**
  * Load properties from document type, tab and document
  *
  * @param integer        $documentTypeId Document type id
  * @param DocumentModel  $document       Document model
  * @param ServiceManager $serviceLocator Service manager
  *
  * @return array
  */
 public function load($documentTypeId, DocumentModel $document, ServiceManager $serviceLocator)
 {
     $tabs = $this->loadTabs($documentTypeId);
     $tabsArray = array();
     $idx = 1;
     foreach ($tabs as $tab) {
         $tabsArray[] = $tab->getName();
         $properties = $this->loadProperties($documentTypeId, $tab->getId(), $document->getId());
         $fieldset = new ZendForm\Fieldset('tabs-' . $idx);
         foreach ($properties as $property) {
             $elements = AbstractForm::addContent($fieldset, Datatype\Model::loadEditor($serviceLocator, $property));
             if (!is_array($elements)) {
                 $elements = array($elements);
             }
             foreach ($elements as $element) {
                 if (empty($element)) {
                     continue;
                 }
                 $element->setOption('required', $property->isRequired());
                 $element->setOption('description', $property->getDescription());
             }
         }
         $this->add($fieldset);
         $idx++;
     }
     $formDocumentAdd = new DocumentInformation();
     $formDocumentAdd->load($document, $serviceLocator->get('Config'));
     $formDocumentAdd->setAttribute('name', 'tabs-' . $idx);
     $this->add($formDocumentAdd);
     return $tabsArray;
 }
예제 #4
0
파일: Model.php 프로젝트: gotcms/gotcms
 /**
  * Load prevalue editor
  *
  * @param AbstractDatatype $datatype Datatype
  *
  * @return Fieldset
  */
 public static function loadPrevalueEditor(AbstractDatatype $datatype)
 {
     $fieldset = new Fieldset('prevalue-editor');
     AbstractForm::addContent($fieldset, $datatype->getPrevalueEditor()->load());
     return $fieldset;
 }
예제 #5
0
 /**
  * Check parent validation
  *
  * @return boolean
  */
 public function isValid()
 {
     if ($this->has('parent')) {
         $this->parentId = (int) $this->get('parent')->getValue();
     }
     $condition = sprintf('parent_id = %d', $this->parentId);
     if (!empty($this->documentId)) {
         $condition .= sprintf(' AND id != %d', $this->documentId);
     }
     $inputFilter = $this->getInputFilter();
     $validators = $inputFilter->get('document-url_key')->getValidatorChain()->getValidators();
     foreach ($validators as $validator) {
         if ($validator['instance'] instanceof Validator\Db\NoRecordExists) {
             $validator['instance']->setExclude($condition);
         }
     }
     return parent::isValid();
 }
예제 #6
0
파일: Editor.php 프로젝트: gotcms/gotcms
 /**
  * Load mixed editor
  *
  * @return string
  */
 public function load()
 {
     $config = $this->getConfig();
     $values = unserialize($this->getValue());
     $datatypes = empty($config['datatypes']) ? array() : $config['datatypes'];
     $datatypesElements = array();
     $lineId = 0;
     if (!empty($values)) {
         foreach ($values as $lineId => $datatypeValue) {
             foreach ($datatypeValue as $datatypeId => $value) {
                 if (empty($datatypes[$datatypeId])) {
                     continue;
                 }
                 $datatypeConfig = $datatypes[$datatypeId];
                 //Get datatypes
                 $object = $this->loadDatatype($datatypeConfig['name']);
                 $editor = $object->getEditor($this->getProperty());
                 if (empty($values[$lineId][$datatypeId])) {
                     $values[$lineId][$datatypeId] = array('value' => '');
                 }
                 $editor->setValue($values[$lineId][$datatypeId]['value']);
                 if (!empty($datatypeConfig['config'])) {
                     $editor->setConfig(serialize($datatypeConfig['config']));
                 }
                 //Initialize prefix
                 $prefix = $this->getName() . '[' . $lineId . '][' . $datatypeId . ']';
                 //Create form
                 $fieldset = new Fieldset($datatypeConfig['name'] . $datatypeId);
                 AbstractForm::addContent($fieldset, $editor->load(), $prefix);
                 $datatypesElements[$lineId][$datatypeId]['label'] = empty($datatypeConfig['label']) ? '' : $datatypeConfig['label'];
                 $datatypesElements[$lineId][$datatypeId]['fieldset'] = $fieldset;
             }
         }
     }
     //Defauts elements
     $template = array();
     foreach ($datatypes as $datatypeId => $datatypeConfig) {
         $datatypeConfig = $datatypes[$datatypeId];
         //Get datatypes
         $object = $this->loadDatatype($datatypeConfig['name']);
         $editor = $object->getEditor($this->getProperty());
         if (empty($values['#{line}'][$datatypeId])) {
             $values['#{line}'][$datatypeId] = array('value' => '');
         }
         $editor->setValue($values['#{line}'][$datatypeId]['value']);
         if (!empty($datatypeConfig['config'])) {
             $editor->setConfig(serialize($datatypeConfig['config']));
         }
         //Initialize prefix
         $prefix = $this->getName() . '[#{line}][' . $datatypeId . ']';
         //Create form
         $fieldset = new Fieldset($datatypeConfig['name'] . $datatypeId);
         $hidden = new Element\Hidden();
         $hidden->setName($prefix . '[name]');
         $hidden->setValue($datatypeConfig['name']);
         $fieldset->add($hidden);
         AbstractForm::addContent($fieldset, $editor->load(), $prefix, '#{line}');
         $template[$datatypeId]['label'] = empty($datatypeConfig['label']) ? '' : $datatypeConfig['label'];
         $template[$datatypeId]['fieldset'] = $fieldset;
     }
     $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/mixed/mixed.css');
     return $this->addPath(__DIR__)->render('mixed-editor.phtml', array('property' => $this->getProperty(), 'datatypes' => $datatypesElements, 'propertyName' => $this->getName(), 'templateElements' => $template));
 }