Inheritance: use trait Illuminate\Support\Traits\Macroable
Exemplo n.º 1
0
 /**
  * Register the application services.
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/config/config.php', 'laform');
     $this->app->bind('laform', 'Karan\\Laform\\Laform');
     if (!$this->app->offsetExists('form')) {
         $this->app->singleton('form', function ($app) {
             // LaravelCollective\HtmlBuilder 5.2 is not backward compatible and will throw an exeption
             // https://github.com/kristijanhusak/laravel-form-builder/commit/a36c4b9fbc2047e81a79ac8950d734e37cd7bfb0
             if (substr(Application::VERSION, 0, 3) == '5.2') {
                 $form = new LaravelForm($app['html'], $app['url'], $app['view'], $app['session.store']->getToken());
             } else {
                 $form = new LaravelForm($app['html'], $app['url'], $app['session.store']->getToken());
             }
             return $form->setSessionStore($app['session.store']);
         });
         if (!$this->aliasExists('Form')) {
             AliasLoader::getInstance()->alias('Form', 'Collective\\Html\\FormFacade');
         }
     }
     if (!$this->app->offsetExists('html')) {
         $this->app->singleton('html', function ($app) {
             return new HtmlBuilder($app['url'], $app['view']);
         });
         if (!$this->aliasExists('Html')) {
             AliasLoader::getInstance()->alias('Html', 'Collective\\Html\\HtmlFacade');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Register the form builder instance.
  *
  * @return void
  */
 protected function registerFormBuilder()
 {
     $this->app->singleton('form', function ($app) {
         $form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken());
         return $form->setSessionStore($app['session.store']);
     });
 }
 /**
  * Register the form builder instance.
  *
  * @return void
  */
 protected function registerFormBuilder()
 {
     $this->app->singleton('form', function ($app) {
         /** @var Store $session */
         $session = $app['session.store'];
         $form = new FormBuilder($app['html'], $app['url'], $session->token());
         $form->setSessionStore($session);
         return $form;
     });
     $this->app->alias('form', 'Collective\\Html\\FormBuilder');
 }
 /**
  * Add Laravel Form to container if not already set
  */
 private function registerFormIfHeeded()
 {
     if (!$this->app->offsetExists('form')) {
         $this->app->singleton('form', function ($app) {
             $form = new LaravelForm($app['html'], $app['url'], $app['view'], $app['session.store']->getToken());
             return $form->setSessionStore($app['session.store']);
         });
         if (!$this->aliasExists('Form')) {
             AliasLoader::getInstance()->alias('Form', 'Collective\\Html\\FormFacade');
         }
     }
 }
 /**
  * Register any application services.
  *
  * This service provider is a great spot to register your various container
  * bindings with the application. As you can see, we are registering our
  * "Registrar" implementation here. You can add your own bindings too!
  *
  * @return void
  */
 public function register()
 {
     parent::register();
     FormBuilder::macro('template', function ($template, $empty = false, $field = 'template') {
         $template_list = '';
         if ($empty) {
             $template_list[''] = '-';
         }
         $folder = base_path() . '/resources/views/site/';
         if (is_dir($folder)) {
             $iterator = new \DirectoryIterator($folder);
             foreach ($iterator as $fileinfo) {
                 if ($fileinfo->isFile() && !$fileinfo->isDot()) {
                     $file = explode('.', $fileinfo->getFilename());
                     array_pop($file);
                     $value = implode('.', $file);
                     $template_list[$value] = $value;
                 }
             }
         }
         if ($template_list) {
             return Form::select($field, $template_list, $template, ['class' => "form-control"]);
         }
         return '';
     });
 }
Exemplo n.º 6
0
 /**
  * Open up a new HTML form and pass the optional novalidate option.
  * This methods relies on the original Form::open method of the Laravel
  * Collective component.
  *
  * @param array $options
  *
  * @return string
  */
 public function open(array $options = array())
 {
     if ($this->novalidate()) {
         $options[] = 'novalidate';
     }
     return parent::open($options);
 }
 /**
  * @param array $options
  *
  * @return string
  */
 public function open(array $options = [])
 {
     $themeName = array_get($options, 'theme', config('rutorika-form.theme'));
     $themeClass = config('rutorika-form.themes.' . $themeName);
     $this->theme = new $themeClass($this);
     $options = $this->theme->updateOptions($options);
     return parent::open($options);
 }
 private function commonInputs($type, $name, $value = null, $options = [])
 {
     return sprintf('
     <div class="input-field col l6 s8 offset-l3 offset-s2">
         %s
         %s
     </div>', parent::input($type, $name, $value, $options), parent::label($name, null, []));
 }
Exemplo n.º 9
0
 /**
  * Get the MessageBag of errors that is populated by the
  * validator.
  *
  * @return \Illuminate\Support\ViewErrorBag
  */
 protected function getErrors()
 {
     $errors = $this->form->getSessionStore()->get('errors');
     if ($errors) {
         return $errors->getBag($this->errorBag);
     }
     return $errors;
 }
Exemplo n.º 10
0
    public function selection($nom, $list = [], $selected = null, $label = null)
    {
        return sprintf('
			<div class="form-group" style="width:200px;">
				%s
				%s
			</div>', $label ? $this->label($nom, $label, ['class' => 'control-label']) : '', parent::select($nom, $list, $selected, ['class' => 'form-control']));
    }
Exemplo n.º 11
0
 public function open(array $options = [])
 {
     if (array_key_exists('model', $options)) {
         PkForm::setModel($options['model']);
         unset($options['model']);
     }
     return parent::open($options);
 }
 public function textarea($name, $value = null, $options = [])
 {
     return sprintf('
     <div class="input-field col l6 s8 offset-l3 offset-s2">
         %s
         %s
     </div>', parent::textarea($name, $value, ['class' => 'materialize-textarea']), parent::label($name, null, []));
 }
 public function close()
 {
     $results = '';
     if (Generator::END == $this->gen->getCodePosition()) {
         $results .= $this->generateClientValidatorCode();
     }
     $results .= parent::close();
     return $results;
 }
Exemplo n.º 14
0
 /**
  * Build all control with the css class, label, and input.
  *
  * @param       $type
  * @param       $name
  * @param null  $value
  * @param array $attributes
  * @param array $options
  * @return string
  */
 public function buildControl($type, $name, $value = null, $attributes = [], $options = [])
 {
     switch ($type) {
         case 'select':
             $options = ['' => config('field-builder.select')] + $options;
             return $this->form->select($name, $options, $value, $attributes);
         case 'password':
             return $this->form->password($name, $attributes);
         case 'checkbox':
             return $this->form->checkbox($name, $value, isset($attributes['checked']), $attributes);
         case 'textarea':
             return $this->form->textarea($name, $value, $attributes);
         case 'number':
             return $this->form->number($name, $value, $attributes);
         case 'radio':
             return $this->form->radio($name, $value, $attributes);
         case 'email':
             return $this->form->email($name, $value, $attributes);
         default:
             return $this->form->input($type, $name, $value, $attributes);
     }
 }
 public function checkbox($name, $value = 1, $checked = null, $options = [])
 {
     return parent::hidden($name, 0) . call_user_func_array('parent::' . __FUNCTION__, func_get_args());
 }
 /**
  *  Create an instance of Mention builder and also call Form Builder's constructor
  * @param HtmlBuilder $html [description]
  * @param UrlGenerator $url [description]
  * @param ViewFactory $view [description]
  */
 public function __construct(HtmlBuilder $html, UrlGenerator $url, ViewFactory $view)
 {
     parent::__construct($html, $url, $view, csrf_token());
 }
 private function registerFormSubmit()
 {
     FormBuilder::macro('button_submit', function ($texte) {
         return FormBuilder::submit($texte, ['class' => 'btn btn-info pull-right']);
     });
 }
Exemplo n.º 18
0
 /**
  * Checks if macro is registered.
  *
  * @param string $name
  * @return bool 
  * @static 
  */
 public static function hasMacro($name)
 {
     return \Collective\Html\FormBuilder::hasMacro($name);
 }
 /**
  * Get the MessageBag of errors that is populated by the
  * validator.
  *
  * @return \Illuminate\Support\MessageBag
  */
 protected function getErrors()
 {
     return $this->form->getSessionStore()->get('errors');
 }
Exemplo n.º 20
0
 /**
  * Creates a color element
  *
  * @param string $name The name of the element
  * @param null   $value
  * @param array  $attributes
  * @return string
  */
 public function color($name, $value = null, $attributes = array())
 {
     $attributes['class'] = isset($attributes['class']) ? self::FORM_CONTROL . ' ' . $attributes['class'] : self::FORM_CONTROL;
     return parent::input('color', $name, $value, $attributes);
 }
Exemplo n.º 21
0
 public function submitButtonIcon($value = null, $options = [])
 {
     $options['class'] = '' . (isset($options['class']) ? ' ' . $options['class'] : '');
     return parent::button($value, $options);
 }
Exemplo n.º 22
0
 /**
  * Set the session store implementation.
  *
  * @param \Illuminate\Session\Store $session
  * @return $this 
  * @static 
  */
 public static function setSessionStore($session)
 {
     return \Collective\Html\FormBuilder::setSessionStore($session);
 }
Exemplo n.º 23
0
 /**
  * Create a button element.
  *
  * @param  string  $value
  * @param  array   $options
  * @return string
  */
 public function button($value = null, $options = array())
 {
     if (!array_key_exists('class', $options)) {
         $options['class'] = 'btn btn-default';
     }
     return parent::button($value, $options);
 }
 /**
  * Create a plain textarea input field.
  *
  * @param  string $name
  * @param  string $value
  * @param  array  $options
  *
  * @return string
  */
 public function plainTextarea($name, $value = null, $options = [])
 {
     return parent::textarea($name, $value, $options);
 }
Exemplo n.º 25
0
 /**
  * Closes form and reset $this->rules
  *
  * @see Collective\Html\FormBuilder
  */
 public function close()
 {
     $this->resetValidation();
     return parent::close();
 }
Exemplo n.º 26
0
 /**
  * Add a checkbox column.
  *
  * @param  array $attributes
  * @return $this
  */
 public function addCheckbox(array $attributes = [])
 {
     $attributes = array_merge(['defaultContent' => '<input type="checkbox" ' . $this->html->attributes($attributes) . '/>', 'title' => $this->form->checkbox('', '', false, ['id' => 'dataTablesCheckbox']), 'data' => 'checkbox', 'name' => 'checkbox', 'orderable' => false, 'searchable' => false, 'exportable' => false, 'printable' => true, 'width' => '10px'], $attributes);
     $this->collection->push(new Column($attributes));
     return $this;
 }
Exemplo n.º 27
0
 /**
  * Dynamically handle calls to the class.
  *
  * @param string $method
  * @param array $parameters
  * @return \Illuminate\Contracts\View\View|mixed 
  * @throws \BadMethodCallException
  * @static 
  */
 public static function componentCall($method, $parameters)
 {
     return \Collective\Html\FormBuilder::componentCall($method, $parameters);
 }
 /**
  * Create a form label element.
  *
  * @param  string $name
  * @param  string $value
  * @param  array $options
  * @return string
  */
 public function label($name, $value = null, $options = [])
 {
     return parent::label($name, $value, $this->appendErrors($name, $options));
 }
Exemplo n.º 29
0
 /**
  * Return the closing form tag.
  *
  * @return string
  */
 public function close()
 {
     return $this->html->close();
 }
Exemplo n.º 30
0
 public function submit($value = null, $options = [])
 {
     $cancelUrl = array_key_exists('cancelUrl', $options) ? $options['cancelUrl'] : null;
     $cancelHtml = '';
     $options = $this->setOptionClasses('', $options, ['btn', 'btn-primary']);
     $controlOptions = $this->getControlOptions(collect($options));
     $controlHtml = parent::submit($value, $controlOptions->toArray());
     if (!is_null($cancelUrl)) {
         $cancelHtml = link_to($cancelUrl, 'Cancel', ['class' => 'btn btn-cancel pull-right']);
     }
     // TODO: render cancel and reset buttons.
     return $this->renderControl('submit', $controlHtml, '', '', $options);
 }