/** * Creates a serie of checkable items * * @param array $_items Items to create */ protected function items($_items) { // If passing an array if (sizeof($_items) == 1 and is_array($_items[0])) { $_items = $_items[0]; } // Iterate through items, assign a name and a label to each $count = 0; foreach ($_items as $name => $label) { // If we haven't any name defined for the checkable, try to compute some if (!is_string($name)) { $name = $this->name; if ($this->checkable == 'checkbox') { $name .= '_' . $count; } } $this->items[] = array('name' => $name, 'label' => Helpers::translate($label)); $count++; } }
/** * Creates a form legend * * @param string $legend The text * @param array $attributes Its attributes * @return string A legend tag */ public static function legend($legend, $attributes = array()) { $legend = Helpers::translate($legend); return '<legend' . \HTML::attributes($attributes) . '>' . $legend . '</legend>'; }
/** * Creates a serie of checkable items * * @param array $_items Items to create */ protected function items($_items) { // If passing an array if (sizeof($_items) == 1 and is_array($_items[0])) { $_items = $_items[0]; } // 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; // 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)); if (isset($attributes)) { $item['attributes'] = $attributes; } $this->items[] = $item; $count++; } }
/** * Ponders a label and a field name, and tries to get the best out of it * * @param string $label A label * @param string $name A field name * @return array A label and a field name */ private function ponder($name, $label) { // Check for the two possibilities if ($label and !$name) { $name = \Str::slug($label); } elseif (!$label and $name) { $label = $name; } // Attempt to translate the label $label = Helpers::translate($label); // Save values $this->name = $name; $this->label = $label; }