You are here

class ExtraFieldManager in Account field split 8

Same name and namespace in other branches
  1. 2.x 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

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_split
View 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

Namesort descending Modifiers Type Description Overrides
ExtraFieldManager::extraFieldInfo public function Return list of extra fields.
ExtraFieldManager::formAlter public function Do form alter.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.