/**
* 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 1.7.0
*/
protected function getName($fieldName)
{
// To support repeated element, extensions can set this in plugin->onRenderSettings
$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;
}
// If the field should support multiple values add the final array segment.
if ($this->multiple) {
switch (strtolower((string) $this->element['type'])) {
case 'text':
case 'textarea':
case 'email':
case 'password':
case 'radio':
case 'calendar':
case 'editor':
case 'hidden':
break;
default:
$name .= '[]';
}
}
return $name;
}