UserFormTestHooks.php

Namespace

Drupal\user_form_test\Hook

File

core/modules/user/tests/modules/user_form_test/src/Hook/UserFormTestHooks.php

View source
<?php

declare (strict_types=1);
namespace Drupal\user_form_test\Hook;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementations for user_form_test.
 */
class UserFormTestHooks {
  
  /**
   * Implements hook_form_FORM_ID_alter() for user_cancel_form().
   */
  public function formUserCancelFormAlter(&$form, &$form_state) : void {
    $form['user_cancel_confirm']['#default_value'] = FALSE;
    $form['access']['#value'] = \Drupal::currentUser()->hasPermission('cancel other accounts');
  }
  
  /**
   * Implements hook_entity_base_field_info_alter().
   */
  public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type) : void {
    if ($entity_type->id() === 'user' && \Drupal::keyvalue('user_form_test')->get('user_form_test_constraint_roles_edit')) {
      $fields['roles']->addConstraint('FieldWidgetConstraint');
    }
  }

}

Classes

Title Deprecated Summary
UserFormTestHooks Hook implementations for user_form_test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.