lithium\template\helper\Form::__construct()
Overrides
lithium\core\Object::__construct()
Constructor.
Parameters
-
array
$config
Configuration options.
Returns
voidSource
public function __construct(array $config = []) {
$defaults = [
'base' => [],
'text' => [],
'textarea' => [],
'select' => ['multiple' => false],
'attributes' => [
'id' => function($method, $name, $options) {
if (in_array($method, ['create', 'end', 'label', 'error'])) {
return;
}
if (!$name || ($method === 'hidden' && $name === '_method')) {
return;
}
$info = $this->binding($name);
$model = $info->class;
$id = Inflector::camelize(Inflector::slug($info->name));
return $model ? basename(str_replace('\\', '/', $model)) . $id : $id;
},
'name' => function($method, $name, $options) {
if (!strpos($name, '.')) {
return $name;
}
$name = explode('.', $name);
$first = array_shift($name);
return $first . '[' . join('][', $name) . ']';
}
],
'binding' => function($object, $name = null) {
$result = compact('name') + [
'data' => null, 'errors' => null, 'class' => null
];
if (is_object($object)) {
$result = compact('name') + [
'data' => $object->data($name),
'errors' => $object->errors($name),
'class' => $object->model()
];
}
return (object) $result;
}
];
parent::__construct(Set::merge($defaults, $config));
}