/**
* Method to get the name used for the field input tag.
*
* @param string $fieldName The field element name.
*
* @return string The name to be used for the field input tag.
*
* @since 3.6
*/
protected function getName($fieldName)
{
$name = '';
// If there is a form control set for the attached form add it first.
if ($this->formControl) {
$name .= $this->formControl;
}
// If the field is in a group add the group control to the field name.
if ($this->group) {
// If we already have a name segment add the group control as another level.
$groups = explode('.', $this->group);
if ($name) {
foreach ($groups as $group) {
$name .= '[' . $group . ']';
}
} else {
$name .= array_shift($groups);
foreach ($groups as $group) {
$name .= '[' . $group . ']';
}
}
}
// If we already have a name segment add the field name as another level.
if ($name) {
$name .= '[' . $fieldName . ']';
} else {
$name .= $fieldName;
}
return $name;
}