for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Propaganistas\LaravelTranslatableBootForms\Form;
use AdamWathan\Form\Elements\Label;
use AdamWathan\Form\FormBuilder as _FormBuilder;
use Propaganistas\LaravelTranslatableBootForms\Form\Binding\BoundData;
class FormBuilder extends _FormBuilder
{
/**
* Array of locale keys.
*
* @var array
*/
protected $locales;
* Sets the available locales for translatable fields.
* @param array $locales
public function setLocales(array $locales)
$this->locales = $locales;
}
public function bind($data)
$this->boundData = new BoundData($data);
boundData
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
* Getting value from Model or ModelTranslation to populate form.
* Courtesy of TypiCMS/TranslatableBootForms (https://github.com/TypiCMS/TranslatableBootForms/blob/master/src/TranslatableFormBuilder.php)
* @param string $name key
* @return string value
protected function getBoundValue($name, $default)
$inputName = preg_split('/[\[\]]+/', $name, - 1, PREG_SPLIT_NO_EMPTY);
if (count($inputName) == 2 && in_array($inputName[0], $this->locales)) {
list($lang, $name) = $inputName;
$value = isset($this->boundData->data()->translate($lang)->{$name})
? $this->boundData->data()->translate($lang)->{$name}
: '';
return $this->escape($value);
return $this->escape($this->boundData->get($name, $default));
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: