$status) { $matches[$key] = substr($status, 1, strlen($status) - 2); } $fielddata['attributes']['options'] = $matches; break; case 'tinyint': preg_match("/\((.*)\)/", $meta['type'], $matches); if ($matches[1] == 1) { $fielddata['type'] = 'checkbox'; break; } case 'integer': $fielddata['type'] = 'number'; break; case 'text': if ($object->isI18nField($meta['name'])) { $fielddata['type'] = 'i18n_textarea'; } else { $fielddata['type'] = 'textarea'; } break; default: if ($object->isI18nField($meta['name'])) { $fielddata['type'] = 'i18n_text'; } else { $fielddata['type'] = 'text'; } } return $fielddata; } /** * Constructor of the Input class. * @param $name * @param $title * @param $value * @param $attributes */ final public function __construct($name, $title, $value, array $attributes = []) { $this->name = $name; $this->title = $title; $this->value = $value; $this->attributes = $attributes; } /** * Sets the parent of this Input object. Usually this is done automatically by the framework in the moment that * the input is initialized in the Form object. So you usually don't need to call this method on your own. * @param Part $parent * @return $this */ public function setParent(Part $parent) { $this->parent = $parent; return $this; } /** * Returns the parent of this Input if there is already one. * @return null|Part */ public function getParent() { return $this->parent; } public function dataMapper($value) { return $value; } /** * Returns the name of the given input. Also have a look at the method getAllInputNames if you want to * provide multiple input elements (like in i18n input fields) within one virtual input. In that case * this getName method returns the main-input name like the attribute in the SORM class. * @return null */ public function getName() { return $this->name; } public function getTitle() { return $this->title; } public function hasValidation() { return $this->validate !== null; } public function getValidationCallback() { return $this->validate; } /** * Returns the value of this input. * @return null */ public function getValue() { return $this->value; } /** * Returns an array with all names of all inputs that this Input-object has. Normally this is just one * name because there is only one input. But if you think of i18n-inputs there are possibly more * textareas - one for each language. In that case this function would return all names of all inputs that * are present. * @return string[] */ public function getAllInputNames() { return [$this->getName()]; } /** * Renders the Input but maybe encapsulated in a template that is displayed only if a condition is true. * This is helpful for the if-attribute on the Input like in setIfCondition. * @return string */ public function renderWithCondition() { if (!$this->permission) { return ''; } $html = $this->render(); if (!trim($html)) { return ''; } if ($this->if !== null) { $html = ''; } return $html; } /** * This renders the Input. * @return string */ abstract public function render(); /** * Returns the context-object which is usually a SimpleORMap object. * @return null|\SimpleORMap */ public function getContextObject() { if ($this->getParent()) { return $this->getParent()->getContextObject(); } return null; } /** * Sets a special mapper-function to turn the request-values into the real values for the database. * @param callable $callback * @return $this */ public function setMapper(Callable $callback) { $this->mapper = $callback; return $this; } /** * Sets the storing function. This would override the normal storing-function that just sets the value * of a given context object like a SORM object. * @param callable $store * @return $this */ public function setStoringFunction(Callable $store) { $this->store = $store; return $this; } /** * Sets the server-side verify function of this input. The callable returns true if the given value is okay, or * false or a textstring representing the error. * @param callable $verify * @return $this */ public function setValidationFunction(Callable $validate) { $this->validate = $validate; return $this; } /** * Sets a condition to display this input. The condition is a javascript condition which is used by vue to * hide the input if the condition is not satisfies. * @param string $if * @return $this */ public function setIfCondition($if) { $this->if = $if; return $this; } /** * Set if the user is able to see and edit this input * @param boolean $if * @return $this */ public function setPermission(bool $permission) { $this->permission = $permission; return $this; } /** * Marks the input as a required field. * @param $required * @return $this */ public function setRequired($required = true) { $this->required = $required; return $this; } /** * Returns the values from the request. Normally this is \Request::get, but special Input-classes could also * return arrays or objects. * @return string|null */ public function getRequestValue() { return \Request::get($this->name); } protected function extractOptionsFromAttributes(array &$attributes) { $options = []; if (isset($attributes['options'])) { $options = $attributes['options']; unset($attributes['options']); } return $options; } }