GcDevelopment\Form\DocumentType::addTab PHP Метод

addTab() публичный Метод

Add tab sub form
public addTab ( mixed $tab ) : DocumentType
$tab mixed \Gc\Tab\Model|array
Результат DocumentType
    public function addTab($tab)
    {
        if (!is_array($tab) and !$tab instanceof Tab\Model) {
            return $this;
        }
        $fieldsets = $this->getTabs();
        $name = new Element\Text('name');
        $description = new Element\Text('description');
        $tabId = new Element\Hidden('tab_id');
        if ($tab instanceof Tab\Model) {
            $name->setValue($tab->getName());
            $description->setValue($tab->getDescription());
            $tabId->setValue($tab->getId());
            $tabFieldsetName = $tab->getId();
        } else {
            $name->setValue($tab['name']);
            $description->setValue($tab['description']);
            $tabId->setValue(str_replace('tab', '', $tab['id']));
            $tabFieldsetName = $tab['id'];
        }
        $tabForm = new FieldSet($tabFieldsetName);
        $fieldsets->add($tabForm);
        $tabForm->add($name);
        $tabForm->add($description);
        $tabForm->add($tabId);
        //Input filter
        $this->getInputFilter()->get('tabs')->add(array('type' => 'Zend\\InputFilter\\InputFilter', 'name' => array('name' => 'name', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'description' => array('name' => 'description', 'required' => true, 'validators' => array(array('name' => 'not_empty')))), $tabFieldsetName);
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testAddTabWithoutValidData()
 {
     $this->assertInstanceOf('GcDevelopment\\Form\\DocumentType', $this->object->addTab('string'));
 }