/** * Get provided field's linked table if it exists * @param string $field The field identifier/name * @return string The linked table */ public static final function getLinkedTable($field) { if (!self::isLinked($field)) { throw new Exception('Field [' . Core\Security::preventInjection($field) . '] is not linked, unable to get table.', E_WARNING, self::getClass()); } $model = self::getField($field)->getModel(); return $model::getTable(); }
/** * Add a new field from model to current form. * Similiar to add() but getting its field object from provided model based on field binding. * @param string $field * @param mixed $value */ public function &addField($fieldname, $value = null) { if ($this->model == null) { throw new Exception('You need to provide a correct Orion\\Core\\Model before using addField()', E_WARNING, get_class($this)); } if (array_key_exists($fieldname, $this->fields)) { throw new Exception('Duplicate field [' . Core\Security::preventInjection($fieldname) . '] during form creation.', E_WARNING, get_class($this)); } $model = $this->model; if (!$model::hasField($fieldname)) { throw new Exception('The field [' . Core\Security::preventInjection($fieldname) . '] does not exist in provided model.', E_WARNING, get_class($this)); } $this->fields[$fieldname] = $model::getField($fieldname); if ($value != null) { $this->fields[$fieldname]->setValue($value); } $this->indexes[] = $fieldname; return $this; }