public function label($fieldName, $text = null, array $options = [])
{
if ($text === null) {
$text = $fieldName;
if (substr($text, -5) === '._ids') {
$text = substr($text, 0, -5);
}
if (strpos($text, '.') !== false) {
$fieldElements = explode('.', $text);
$text = array_pop($fieldElements);
}
if (substr($text, -3) === '_id') {
$text = substr($text, 0, -3);
}
$text = __(Inflector::humanize(Inflector::underscore($text)));
}
if (isset($options['for'])) {
$labelFor = $options['for'];
unset($options['for']);
} else {
$labelFor = $this->_domId($fieldName);
}
$attrs = $options + ['for' => $labelFor, 'text' => $text];
if (isset($options['input'])) {
if (is_array($options['input'])) {
$attrs = $options['input'] + $attrs;
}
return $this->widget('nestingLabel', $attrs);
}
return $this->widget('label', $attrs);
}