Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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'));
 }
Exemplo n.º 8
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++;
     }
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
 /**
  * Add a placeholder to the current select
  *
  * @param  string $placeholder The placeholder text
  */
 public function placeholder($placeholder)
 {
     $this->placeholder = Helpers::translate($placeholder);
     return $this;
 }
Exemplo n.º 12
0
 /**
  * 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;
 }