public function FlexiformElementUserName::form in Flexiform 7
Return the form element for this FlexiformElement.
Overrides FlexiformElement::form
File
- includes/
element/ user_name.element.inc, line 15 - Contains class for the User name element.
Class
- FlexiformElementUserName
- Class to add the node title field to a form.
Code
public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
$parents = $form['#parents'];
$parents[] = 'name';
// Support email registration behaviour by optionally creating a hidden
// element containing an autogenerated user name.
if (module_exists('email_registration') && (!isset($this->settings['email_registration']) || !empty($this->settings['email_registration']))) {
$form[$this->element_namespace] = array(
'#type' => 'hidden',
'#parents' => $parents,
'#title' => $this
->label(),
'#value' => !empty($entity->name) ? $entity->name : 'email_registration_' . user_password(),
'#required' => TRUE,
);
return parent::form($form, $form_state, $entity);
}
// Work out the default value.
$default = '';
if (!empty($this->settings['default_value']['default_value'])) {
$default = $this->settings['default_value']['default_value'];
}
if (!empty($this->settings['default_value']['use_tokens'])) {
$default = $this
->replaceCtoolsSubstitutions($default, $form['#flexiform_entities']);
}
$form[$this->element_namespace] = array(
'#type' => 'textfield',
'#parents' => $parents,
'#title' => $this
->label(),
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'username',
),
),
'#default_value' => !empty($entity->name) ? $entity->name : $default,
'#maxlength' => 255,
);
$form = parent::form($form, $form_state, $entity);
return $form;
}