Username.php in User protect 8
File
src/Plugin/UserProtection/Username.php
View source
<?php
namespace Drupal\userprotect\Plugin\UserProtection;
use Drupal\Core\Form\FormStateInterface;
class Username extends UserProtectionBase {
public function applyAccountFormProtection(array &$form, FormStateInterface $form_state) {
$build_info = $form_state
->getBuildInfo();
$account = $build_info['callback_object']
->getEntity();
if ($account
->getAccountName() && isset($form['account']['name'])) {
$form['account']['name']['#disabled'] = TRUE;
$form['account']['name']['#value'] = $account
->getAccountName();
return TRUE;
}
return FALSE;
}
}