/** * Opens a control group * * @return string Opening tag */ private function open() { // If any errors, set state to errors $errors = Former::getErrors(); if ($errors) { $this->state('error'); } // Retrieve state and append it to classes if ($this->state) { $this->attributes = Helpers::addClass($this->attributes, $this->state); } // Required state if (Former::field()->isRequired()) { $this->attributes = Helpers::addClass($this->attributes, Config::get('required_class')); } return '<div' . HTML::attributes($this->attributes) . '>'; }
/** * Translates a string by trying several fallbacks * * @param string $key The key to translate * @param string $fallback The ultimate fallback * @return string A translated string */ public static function translate($key, $fallback = null) { // If nothing was given, return nothing, bitch if (!$key) { return null; } // If no fallback, use the key if (!$fallback) { $fallback = $key; } // Assure we don't already have a Lang object if ($key instanceof Lang) { return $key->get(); } // Search for the key itself $translation = Lang::line($key)->get(null, ''); // If not found, search in the field attributes if (!$translation) { $translation = Lang::line(Config::get('translate_from') . '.' . $key)->get(null, $fallback); } return ucfirst($translation); }
/** * Set up a Field instance * * @param string $type A field type */ public function __construct($type, $name, $label, $value, $attributes) { // Set base parameters $this->attributes = (array) $attributes; $this->label = $label; $this->name = $name; $this->type = $type; $this->value = $value; // Set magic parameters (repopulated value, translated label, etc) if (Config::get('automatic_label')) { $this->ponder($name, $label); } if ($type != 'password') { $this->value = $this->repopulate(); } if (Config::get('live_validation')) { $this->addRules(); } // Link Control group if (Framework::isnt(null)) { $this->controlGroup = new ControlGroup($this->label); } }
/** * Change the framework currently being used by Former * * @param string $framework A framework, or null for none */ public static function useFramework($framework = null) { if (in_array($framework, array('bootstrap', 'zurb')) or is_null($framework)) { Config::set('framework', $framework); } return static::current(); }
/** * Fetch options from both Former and the user */ public function __construct() { $defaultOptions = Conf::get('former::former'); $userOptions = (array) Conf::get('former'); static::$options = array_merge($defaultOptions, $userOptions); }
<?php use Former\Config; use Former\Framework; // Loading Former -------------------------------------------------- / Autoloader::namespaces(array('Former' => Bundle::path('former') . 'libraries')); // Loading Former configuration ------------------------------------ / // Fetch configuration files new Config(); // Set default framework Framework::useFramework(Config::get('framework'));
public static function renderLabel($label, $field) { // Get the label and its informations extract($label); // Add classes to the attributes $attributes = Framework::getLabelClasses($attributes); // Append required text if ($field->isRequired()) { $label .= Config::get('required_text'); } // Get the field name to link the label to it if ($field->isCheckable()) { return '<label' . HTML::attributes($attributes) . '>' . $label . '</label>'; } return \Form::label($field->name, $label, $attributes); }