public function normalize($input, $property, model_editor $editor) { if ($this->isReadOnly) { return null; } // don't normalize input provided by editor, but separately read input // from multiple included fields $field = $editor->propertyToField($property); $amount = trim(input::vget("{$field}_amount")); $currency = trim(input::vget("{$field}_currency")); // consider missing monetary input if amount is empty if ($amount === '') { return null; } if (array_key_exists($currency, static::$currencies)) { // normalize entered amount according to provided set of supported notations foreach (static::$amountNotations as $amountPattern) { if (preg_match($amountPattern, $amount, $matches)) { return sprintf('%s%s.%02d %s', $matches[1] == '-' ? '-' : '', strtr($matches[2], array('.' => '', ',' => '')), $matches[3], $currency); } } } // provide amount w/o currency as fallback (causing validation failure) return $amount; }
public function performEdit() { if (!user::current()->isAuthenticated()) { throw new http_exception(403); } $this->prepareControl(); if (is_callable($this->viewCustomizer)) { call_user_func($this->viewCustomizer, $this, true); } else { $authenticated = user::current()->isAuthenticated(); $this->editor->mayEdit($authenticated)->mayDelete($authenticated); } if ($this->editor->isEditable()) { $this->editor->form()->post(); } if ($this->editor->processInput($this->editorValidator)) { txf::redirectTo($this->getUrls()->list); } return $this->editor->render(); }
/** * 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; }
public function setEditor(model_editor $editor) { $editor->form()->post(); return parent::setEditor($editor); }
public function onDeleting(model_editor $editor, model $item, model_editor_field $field) { $datasource = $editor->source(); $existing = $this->_getSelectorOfExisting(); // 1) drop all previously existing bindings $this->_unbindSelected($datasource, $existing); }