<?php

/**
 * @file
 * Contains admin_menus.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function ouatt_users_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the editors_menus module.
    case 'help.page.ouatt_users':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Où Atterrir users twicks module') . '</p>';
      return $output;

    default:
  }
}


/**
 * Implements hook_form_FORM_ID_alter().
 */
function ouatt_users_form_user_register_form_alter(&$form, $form_state, $form_id) {
  $curuser = \Drupal::currentUser();
  $curroles = $curuser->getRoles();
  if ( in_array('group_admin', $curroles) && !in_array(['admin', 'root'], $curroles) ){
    // role. Group admin can only create "groupe member" user
    $form['role_change']['widget']['#default_value'] = ['group_member'];
    $form['role_change']['#disabled'] = true;
    $form['role_change']['#attributes']['class'][] = 'js-hide';
    // status. Always active
    $form['account']['status']['#default_value'] = 1;
    $form['account']['status']['#disabled'] = true;
    $form['account']['status']['#attributes']['class'][] = 'js-hide';
  }

}