Get if property is required or not
public isRequired ( boolean $value = null ) : mixed | ||
$value | boolean | Value |
리턴 | mixed |
/** * Test * * @return void */ public function testSaveValue() { $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => 0)); $documentModel->save(); $this->object->setDocumentId($documentModel->getId()); $this->assertTrue($this->object->saveValue()); $this->object->isRequired(true); $this->assertFalse($this->object->saveValue()); }
/** * Save properties * * @param Zend\InputFilter\InputFilter $propertiesSubform Properties sub form * @param array $existingTabs Array of tabs * * @return array */ protected function saveProperties($propertiesSubform, $existingTabs) { $existingProperties = array(); $idx = 0; foreach ($propertiesSubform->getValidInput() as $propertyId => $propertyValues) { if (!preg_match('~^property(\\d+)$~', $propertyId, $matches)) { continue; } $propertyId = $matches[1]; $propertyModel = Property\Model::fromId($propertyId); if (empty($propertyModel) or !in_array($propertyModel->getTabId(), $existingTabs)) { $propertyModel = new Property\Model(); } $propertyModel->setDescription($propertyValues->getValue('description')); $propertyModel->setName($propertyValues->getValue('name')); $propertyModel->setIdentifier($propertyValues->getValue('identifier')); $propertyModel->setTabId($existingTabs[$propertyValues->getValue('tab')]); $propertyModel->setDatatypeId($propertyValues->getValue('datatype')); $required = $propertyValues->getValue('required'); $propertyModel->isRequired(!empty($required) ? true : false); $propertyModel->setSortOrder(++$idx); $propertyModel->save(); $existingProperties[] = $propertyModel->getId(); } return $existingProperties; }