Example #1
0
    /**
     * Build and render a field
     *
     * @param string $type
     * @param string $name
     * @param mixed $value
     * @param array $attributes
     * @param array|null $options
     * @return string
     */
    protected function doBuild($type, $name, $value = null, $attributes = array(), $options = null)
    {
        $attributes = $this->replaceAttributes($attributes);

        if (!$this->checkAccess($attributes)) {
            return '';
        }

        $required = $this->getRequired($attributes);
        $label = $this->getLabel($name, $attributes);
        $htmlName = $this->getHtmlName($name);
        $id = $this->getHtmlId($name);
        $errors = $this->getControlErrors($id);
        $hasErrors = !empty($errors);
        $customTemplate = $this->getCustomTemplate($attributes);

        $attributes = $this->getHtmlAttributes($type, $attributes, $errors, $id, $required);

        $input = $this->buildControl($type, $name, $value, $attributes, $options, $htmlName);

        return $this->theme->render(
            $customTemplate,
            compact('htmlName', 'id',  'label', 'input', 'errors', 'hasErrors', 'required'),
            'fields.'.$this->getDefaultTemplate($type)
        );
    }
Example #2
0
 /**
  * Clear and render the alert messages of this and the previous requests.
  *
  * @param string|null $custom
  * @return string
  */
 public function render($custom = null)
 {
     $messages = $this->toArray();
     if (!empty($messages)) {
         $this->clearMessages();
         return $this->theme->render($custom, ['messages' => $this->withDefaults($messages)], 'alert');
     }
     return '';
 }
Example #3
0
 /**
  * Create a list of checkboxes.
  *
  * This function is similar to Form::select, but it generates a collection
  * of checkboxes instead of options.
  *
  * i.e. Form::checkboxes('status', ['a' => 'Active', 'i' => 'Inactive']);
  *
  * You can pass 'inline' as a value of the attribute's array, to set the
  * checkboxes as inline (they'll be rendered using the 'checkboxes-inline'
  * template).
  *
  * @param string $name
  * @param array  $options
  * @param string $selected
  * @param array  $attributes
  *
  * @return string
  */
 public function checkboxes($name, $options = array(), $selected = null, $attributes = array())
 {
     $selected = $this->getValueAttribute($name, $selected);
     if (is_null($selected)) {
         $selected = array();
     }
     $defaultTemplate = in_array('inline', $attributes) ? 'forms.checkboxes-inline' : 'forms.checkboxes';
     $template = isset($attributes['template']) ? $attributes['template'] : null;
     $checkboxes = [];
     foreach ($options as $value => $label) {
         $checkboxes[] = ['name' => $name . '[]', 'value' => $value, 'label' => $label, 'checked' => is_array($selected) && in_array($value, $selected), 'id' => $name . '_' . Str::slug($value)];
     }
     unset($attributes['inline'], $attributes['template']);
     return $this->theme->render($template, compact('name', 'checkboxes', 'attributes'), $defaultTemplate);
 }
Example #4
0
 /**
  * Renders a new menu
  *
  * @param string|null $customTemplate
  * @return string the menu's HTML
  */
 public function render($customTemplate = null)
 {
     $items = $this->generateItems($this->items);
     return $this->theme->render($customTemplate, ['items' => $items, 'class' => $this->class], 'menu');
 }