예제 #1
0
 /**
  * Add a class to the current field
  *
  * @param string $class The class to add
  */
 public function addClass($class)
 {
     if (is_array($class)) {
         $class = implode(' ', $class);
     }
     $this->attributes = \Former\Helpers::addClass($this->attributes, $class);
     return $this;
 }
예제 #2
0
파일: Input.php 프로젝트: autocar/former
 /**
  * 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;
 }
예제 #3
0
 /**
  * Create a label element from a string
  *
  * @param string $label
  * @param string $field
  *
  * @return Element
  */
 protected function createLabel($label, $field = null)
 {
     if ($label instanceof Element) {
         $label = $label->getValue();
     }
     $label = Helpers::translate($label);
     $label = Element::create('label', $label)->for($field ?: strtolower($label));
     $label->addClass($this->app['former.framework']->getLabelClasses());
     return $label;
 }
예제 #4
0
 /**
  * Render the FormerObject 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();
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
 public function testCanDisableTranslationCapitalization()
 {
     $this->app['config'] = Mockery::mock('Config')->shouldReceive('get')->with('former.live_validation', '')->andReturn(true)->shouldReceive('get')->with('former.translate_from', '')->andReturn(true)->shouldReceive('get')->with('former.automatic_label', '')->andReturn(true)->shouldReceive('get')->with('former.capitalize_translations', '')->andReturn(false)->mock();
     Helpers::setApp($this->app);
     $this->assertEquals('field', Helpers::translate('field'));
 }
예제 #7
0
 /**
  * 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 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++;
     }
 }
예제 #8
0
파일: Hidden.php 프로젝트: autocar/former
 /**
  * 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();
 }
예제 #9
0
파일: Field.php 프로젝트: autocar/former
 /**
  * Redirect calls to the group if necessary
  *
  * @param string $method
  */
 public function __call($method, $parameters)
 {
     // Translate attributes
     $translatable = $this->app['former']->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);
 }
예제 #10
0
 /**
  * Prints out the current tag
  *
  * @return string An uneditable input tag
  */
 public function __toString()
 {
     $this->attributes = Helpers::addClass($this->atteibutes, 'uneditable-input');
     return '<span' . HTML::attributes($attributes) . '>' . HTML::entities($value) . '</span>';
 }
 /**
  * Bind Former classes to the container
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindFormer(Container $app)
 {
     // Add config namespace
     $configPath = __DIR__ . '/../config/former.php';
     $this->mergeConfigFrom($configPath, 'former');
     $this->publishes([$configPath => $app['path.config'] . '/former.php']);
     $framework = $app['config']->get('former.framework');
     $app->bind('former.framework', function ($app) {
         return $app['former']->getFrameworkInstance($app['config']->get('former.framework'));
     });
     $app->singleton('former.populator', function ($app) {
         return new Populator();
     });
     $app->singleton('former.dispatcher', function ($app) {
         return new MethodDispatcher($app, Former::FIELDSPACE);
     });
     $app->singleton('former', function ($app) {
         return new Former($app, $app->make('former.dispatcher'));
     });
     $app->alias('former', 'Former\\Former');
     Helpers::setApp($app);
     return $app;
 }
예제 #12
0
파일: Button.php 프로젝트: iyoworks/former
 /**
  * Hijack Former's Object model value method
  *
  * @param  string $value The new button text
  */
 public function value($value)
 {
     $value = \Former\Helpers::translate($value);
     $this->value = $value;
     return $this;
 }
예제 #13
0
 /**
  * Bind Former classes to the container.
  *
  * @param Container $app
  *
  * @return Container
  */
 public function bindFormer(Container $app)
 {
     $framework = $app['config']->get('former.framework');
     $app->bind('former.framework', function ($app) {
         return $app['former']->getFrameworkInstance($app['config']->get('former.framework'));
     });
     $app->singleton('former.populator', function ($app) {
         return new \Former\Populator();
     });
     $app->singleton('former.dispatcher', function ($app) {
         return new \Former\MethodDispatcher($app, \Former\Former::FIELDSPACE);
     });
     $app->singleton('former', function ($app) {
         return new \Former\Former($app, $app->make('former.dispatcher'));
     });
     $app->alias('former', 'Former\\Former');
     \Former\Helpers::setApp($app);
     return $app;
 }
예제 #14
0
 /**
  * Bind Former classes to the container
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindFormer(Container $app)
 {
     // Add config namespace
     $app['config']->package('anahkiasen/former', __DIR__ . '/../config');
     $app->bind('former.framework', function ($app) {
         return $app['former']->getFrameworkInstance($app['config']->get('former::framework'));
     });
     $app->singleton('former.populator', function ($app) {
         return new Populator();
     });
     $app->singleton('former.dispatcher', function ($app) {
         return new MethodDispatcher($app, Former::FIELDSPACE);
     });
     $app->singleton('former', function ($app) {
         return new Former($app, $app->make('former.dispatcher'));
     });
     Helpers::setApp($app);
     return $app;
 }
예제 #15
0
파일: Field.php 프로젝트: raftalks/former
 /**
  * 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 is_null($name)) {
         $name = \Str::slug($label);
     } elseif (is_null($label) and $name) {
         $label = $name;
     }
     // Attempt to translate the label
     $label = Helpers::translate($label);
     // Save values
     $this->name = $name;
     $this->label = $label;
 }
예제 #16
0
파일: Input.php 프로젝트: raftalks/former
 /**
  * Render a text element as a search element
  */
 private function asSearch()
 {
     $this->type = 'text';
     $this->attributes = Helpers::addClass($this->attributes, 'search-query');
 }
예제 #17
0
파일: Select.php 프로젝트: GhDj/erp-fac-fin
 /**
  * Add a placeholder to the current select
  *
  * @param  string $placeholder The placeholder text
  */
 public function placeholder($placeholder)
 {
     $this->placeholder = Helpers::translate($placeholder);
     return $this;
 }
예제 #18
0
 /**
  * Add an block help
  *
  * @param  string $help       The help text
  * @param  array  $attributes Facultative attributes
  */
 public function blockHelp($help, $attributes = array())
 {
     // If no help text, do nothing
     if (empty($help)) {
         return false;
     }
     // Attempt to translate help text
     $help = Helpers::translate($help);
     $this->help['block'] = Framework::blockHelp($help, $attributes);
 }
예제 #19
0
파일: Button.php 프로젝트: autocar/former
 /**
  * Hijack Former's Object model value method
  *
  * @param  string $value The new button text
  */
 public function value($value)
 {
     $this->value = Helpers::translate($value);
     return $this;
 }
예제 #20
0
 /**
  * Add the correct classes to a group
  *
  * @param  array $attributes The group's attributes
  * @return array             The modified attributes
  */
 public static function getGroupClasses($attributes)
 {
     if (static::is('bootstrap')) {
         $attributes = Helpers::addClass($attributes, 'control-group');
     }
     return $attributes;
 }
예제 #21
0
 /**
  * Adds a label
  *
  * @param  string $label A label
  * @return ControlGroup
  */
 public function setLabel($label, $attributes = array())
 {
     // Attempt to translate the label
     $label = Helpers::translate($label);
     // Set control-group label
     $this->label = array('label' => $label, 'attributes' => $attributes);
 }
예제 #22
0
파일: Group.php 프로젝트: autocar/former
 /**
  * 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;
 }
예제 #23
0
 /**
  * Bind Former classes to the container
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindFormer(Container $app)
 {
     // Add config namespace
     $app['config']->package('anahkiasen/former', __DIR__ . '/../config');
     // Get framework to use
     $framework = $app['config']->get('former::framework');
     $frameworkClass = '\\Former\\Framework\\' . $framework;
     $app->bind('former.framework', function ($app) use($frameworkClass) {
         return new $frameworkClass($app);
     });
     $app->singleton('former.populator', function ($app) {
         return new Populator();
     });
     $app->singleton('former', function ($app) {
         return new Former($app, new MethodDispatcher($app, Former::FIELDSPACE));
     });
     Helpers::setApp($app);
     return $app;
 }