class ExtraFieldManager in Account field split 2.x
Same name and namespace in other branches
- 8 src/ExtraFieldManager.php \Drupal\account_field_split\ExtraFieldManager
Class ExtraFieldManager.
Split User useless "User name and password" field into extra fields which could be managed separately.
Hierarchy
- class \Drupal\account_field_split\ExtraFieldManager uses StringTranslationTrait
Expanded class hierarchy of ExtraFieldManager
1 file declares its use of ExtraFieldManager
- account_field_split.module in ./
account_field_split.module - account_field_split module hooks and alters.
File
- src/
ExtraFieldManager.php, line 15
Namespace
Drupal\account_field_splitView source
class ExtraFieldManager {
use StringTranslationTrait;
/**
* Do form alter.
*/
public function formAlter(array &$form, FormStateInterface &$form_state, $form_id) {
if (isset($form['account']) && is_array($form['account'])) {
$account_elements = Element::children($form['account']);
foreach ($account_elements as $account_element) {
if (isset($form['account'][$account_element])) {
$form[$account_element] = $form['account'][$account_element];
unset($form['account'][$account_element]);
}
}
}
}
/**
* Return list of extra fields.
*
* @return array
* Array of extra fields description.
*/
public function extraFieldInfo() {
$extra = [];
$fields = [
'mail' => 'E-mail address',
'name' => 'Username',
'pass' => 'Password',
'status' => 'Status',
'roles' => 'Roles',
'notify' => 'Notify user about new account',
'current_pass' => 'Current password',
];
$description = $this
->t('User profile element');
foreach ($fields as $field => $label) {
$extra['user']['user']['form'][$field] = [
'label' => $label,
'description' => $description,
'weight' => 0,
'visible' => TRUE,
];
}
return $extra;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtraFieldManager:: |
public | function | Return list of extra fields. | |
ExtraFieldManager:: |
public | function | Do form alter. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |