/** * Adds a label to the group * * @param string $label A label */ public function setLabel($label) { if (!$label instanceof Element) { $label = Helpers::translate($label); $label = Element::create('label', $label)->for($label); } $this->label = $label; }
/** * Add a placeholder to the current select * * @param string $placeholder The placeholder text */ public function placeholder($placeholder) { $this->placeholder = Helpers::translate($placeholder); return $this; }
/** * Creates a form legend * * @param string $legend The text * @param array $attributes Its attributes * * @return Element A <legend> tag */ public function legend($legend, $attributes = array()) { $legend = Helpers::translate($legend); return Element::create('legend', $legend, $attributes); }
/** * Hijack Form's Object model value method * * @param string $value The new button text */ public function value($value) { $this->value = Helpers::translate($value); return $this; }
/** * Creates a series of checkable items * * @param array $_items Items to create */ protected function items($_items) { // If passing an array if (sizeof($_items) == 1 and isset($_items[0]) and is_array($_items[0])) { $_items = $_items[0]; } // Fetch models if that's what we were passed if (isset($_items[0]) and is_object($_items[0])) { $_items = Helpers::queryToArray($_items); $_items = array_flip($_items); } // Iterate through items, assign a name and a label to each $count = 0; foreach ($_items as $label => $name) { // Define a fallback name in case none is found $fallback = $this->isCheckbox() ? $this->name . '_' . $count : $this->name; // Grouped fields if ($this->isGrouped()) { $attributes['id'] = str_replace('[]', null, $fallback); $fallback = str_replace('[]', null, $this->name) . '[]'; } // If we haven't any name defined for the checkable, try to compute some if (!is_string($label) and !is_array($name)) { $label = $name; $name = $fallback; } // If we gave custom information on the item, add them if (is_array($name)) { $attributes = $name; $name = array_get($attributes, 'name', $fallback); unset($attributes['name']); } // Store all informations we have in an array $item = array('name' => $name, 'label' => Helpers::translate($label), 'count' => $count); if (isset($attributes)) { $item['attributes'] = $attributes; } $this->items[] = $item; $count++; } }
/** * Redirect calls to the group if necessary * * @param string $method */ public function __call($method, $parameters) { // Translate attributes $translatable = $this->app['form']->getOption('translatable', array()); if (in_array($method, $translatable) and isset($parameters[0])) { $parameters[0] = Helpers::translate($parameters[0]); } // Redirect calls to the Control Group if (method_exists($this->group, $method) or Str::startsWith($method, 'onGroup')) { $method = str_replace('onGroup', '', $method); $method = lcfirst($method); call_user_func_array(array($this->group, $method), $parameters); return $this; } return parent::__call($method, $parameters); }