Example #1
0
 public function validate($input, $property, model_editor $editor)
 {
     parent::validate($input, $property, $editor);
     if ($input != '') {
         if (!mail::isValidAddress($input)) {
             throw new \InvalidArgumentException(\de\toxa\txf\_L('This is not a valid e-mail address.'));
         }
     }
     return true;
 }
Example #2
0
File: url.php Project: cepharum/txf
 public function validate($input, $property, model_editor $editor)
 {
     parent::validate($input, $property, $editor);
     if ($input != '') {
         if (!url::isFile($input)) {
             throw new \InvalidArgumentException(\de\toxa\txf\_L('This is not a valid URL.'));
         }
         if ($this->absolute && url::isRelative($input)) {
             throw new \InvalidArgumentException(\de\toxa\txf\_L('This URL must be absolute. Include scheme e.g. http://www.example.com/!'));
         }
     }
     return true;
 }
Example #3
0
 /**
  * Creates model editor used for editing page.
  *
  * @param string $editorName name of editor
  * @return model_editor created instance
  */
 protected function createEditor($editorName)
 {
     $page = $this->getPage();
     if ($page) {
         $editor = model_editor::createOnItem($this->dataSource, $page, $editorName);
         $pageName = $page->name;
     } else {
         $editor = model_editor::createOnModel($this->dataSource, $this->modelClass, $editorName);
         $pageName = $this->pageName;
     }
     $editor->addField('name', \de\toxa\txf\_L('Name'), model_editor_static::create()->setContent($pageName))->fixProperty('name', $pageName)->addField('title', \de\toxa\txf\_L('Title'), model_editor_text::create()->maximum(255)->trim(true)->collapseWhitespace(true)->mandatory())->addField('content', \de\toxa\txf\_L('Content'), model_editor_texteditor::create(10, 60)->mandatory()->setClass('rte'));
     return $editor;
 }
Example #4
0
 public function setEditor(model_editor $editor)
 {
     $editor->form()->post();
     return parent::setEditor($editor);
 }
Example #5
0
 /**
  * Adds field for editing named property of associated item using provided
  * editor element.
  *
  * @param string $propertyName name of property to edit using provided editor element
  * @param string|null $label label to use on field
  * @param model_editor_element $type editor element to use on adjusting property
  * @return $this
  */
 public function addField($propertyName, $label = null, model_editor_element $type = null)
 {
     $propertyName = trim($propertyName);
     if (!$this->class->getMethod('isPropertyName')->invoke(null, $propertyName)) {
         $isRelation = false;
         if ($type instanceof model_editor_related) {
             try {
                 $this->class->getMethod('relation')->invoke(null, $propertyName);
                 $isRelation = true;
             } catch (\InvalidArgumentException $e) {
             }
         }
         if (!$isRelation) {
             throw new \InvalidArgumentException('no such property in associated model: ' . $propertyName);
         }
     }
     if ($type === null) {
         $type = new model_editor_text();
     }
     $type->setEditor($this);
     if ($label === null) {
         $label = $this->class->getMethod('nameToLabel')->invoke(null, $propertyName);
     }
     if (trim($label) === '') {
         throw new \InvalidArgumentException('missing label on editor property: ' . $propertyName);
     }
     $fieldName = $this->propertyToField($propertyName);
     if (array_key_exists($fieldName, $this->fields)) {
         throw new \InvalidArgumentException('field exists already');
     }
     $field = new model_editor_field($fieldName, $label, $type);
     $this->fields[$fieldName] = $field;
     if ($this->item) {
         // ensure field may act on selecting particular item (done before)
         $type->onSelectingItem($this, $this->item, $field);
     }
     return $this;
 }