/** * Adds a datalist to the current field * * @param array $datalist An array to use a source * @param string $value The field to use as value * @param string $key The field to use as key */ public function useDatalist($datalist, $value = null, $key = null) { $datalist = Helpers::queryToArray($datalist, $value, $key); $list = $this->list ?: 'datalist_' . $this->name; // Create the link to the datalist $this->list = $list; $this->datalist = $datalist; return $this; }
/** * Render the FormObject and set its id * * @return string */ public function render() { // Set the proper ID according to the label $this->setId(); // Encode HTML value $isButton = $this instanceof Field ? $this->isButton() : false; if (!$isButton and is_string($this->value)) { $this->value = Helpers::encode($this->value); } return parent::render(); }
/** * 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); }
/** * Bind Form classes to the container * * @param Container $app * * @return Container */ public function bindForm(Container $app) { // Add config namespace $configPath = __DIR__ . '/../config/form.php'; $this->mergeConfigFrom($configPath, 'form'); $this->publishes([$configPath => $app['path.config'] . '/form.php']); $framework = $app['config']->get('form.framework'); $app->bind('form.framework', function ($app) { return $app['form']->getFrameworkInstance($app['config']->get('form.framework')); }); $app->singleton('form.populator', function ($app) { return new Populator(); }); $app->singleton('form.dispatcher', function ($app) { return new MethodDispatcher($app, Form::FIELDSPACE); }); $app->singleton('form', function ($app) { return new Form($app, $app->make('form.dispatcher')); }); $app->alias('form', 'Form\\Form'); Helpers::setApp($app); return $app; }
/** * 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; }
/** * Outputs a hidden field * * @return string An <input type="hidden" /> */ public function render() { return HtmlInput::create('hidden', $this->name, Helpers::encode($this->value), $this->attributes)->render(); }
/** * 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); }