function _name_render_component in Name Field 7
Same name and namespace in other branches
- 6 name.module \_name_render_component()
Helper function to render a component within a name element.
Parameters
array $components: Core properties for all components.
string $component_key: The component key of the component that is being rendered.
array $base_element: Base FAPI element that makes up a name element.
bool $core: Flag that indicates that the component is required as part of a valid name.
Return value
array The constructed component FAPI structure for a name element.
1 call to _name_render_component()
- name_element_expand in ./
name.module - The #process callback to create the element.
File
- ./
name.module, line 672 - Defines an API for displaying and inputing names.
Code
function _name_render_component($components, $component_key, $base_element, $core) {
$component = $components[$component_key];
$element = array();
// Allow other modules to append additional FAPI properties to the element.
foreach (element_properties($component) as $key) {
$element[$key] = $component[$key];
}
$element['#attributes']['class'][] = 'name-element';
$element['#attributes']['class'][] = 'name-' . $component_key;
if ($core) {
$element['#attributes']['class'][] = 'name-core-component';
}
if (isset($component['attributes'])) {
foreach ($component['attributes'] as $key => $attribute) {
if (isset($element['#attributes'][$key])) {
if (is_array($attribute)) {
$element['#attributes'][$key] = array_merge($element['#attributes'][$key], $attribute);
}
else {
$element['#attributes'][$key] .= ' ' . $attribute;
}
}
else {
$element['#attributes'][$key] = $attribute;
}
}
}
$base_attributes = array(
'type',
'title',
'size',
'maxlength',
);
foreach ($base_attributes as $key) {
$element['#' . $key] = $component[$key];
}
$element['#default_value'] = $base_element['#value'][$component_key];
if ($component['type'] == 'select') {
$element['#options'] = $component['options'];
$element['#size'] = 1;
}
elseif (!empty($component['autocomplete'])) {
$element['#autocomplete_path'] = $component['autocomplete'];
}
if ($core && !empty($base_element['#show_component_required_marker'])) {
$element['#title'] .= theme('name_component_required_marker', array(
'components' => $components,
'component_key' => $component_key,
'base_element' => $base_element,
));
}
// Enable the title options.
$title_display = isset($component['title_display']) ? $component['title_display'] : 'description';
switch ($title_display) {
case 'title':
break;
case 'placeholder':
$element['#attributes']['placeholder'] = t($element['#title']);
$element['#title_display'] = 'invisible';
break;
case 'none':
$element['#title_display'] = 'invisible';
break;
case 'description':
default:
$element['#title_display'] = 'invisible';
$element['#description'] = t($element['#title']);
break;
}
return $element;
}