user_cancel_methods example


  public function getConfirmText() {
    return $this->t('Confirm');
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $user = $this->currentUser();
    $this->cancelMethods = user_cancel_methods();

    // Display account cancellation method selection, if allowed.     $own_account = $this->entity->id() == $user->id();
    $this->selectCancel = $user->hasPermission('administer users') || $user->hasPermission('select account cancellation method');

    $form['user_cancel_method'] = [
      '#type' => 'radios',
      '#title' => $own_account ? $this->t('When cancelling your account') : $this->t('Cancellation method'),
      '#access' => $this->selectCancel,
    ];
    $form['user_cancel_method'] += $this->cancelMethods;

    
// Display account cancellation method selection, if allowed.     $user = $this->currentUser();
    $selectCancel = $user->hasPermission('administer users') || $user->hasPermission('select account cancellation method');

    $form['user_cancel_method'] = [
      '#type' => 'radios',
      '#title' => $this->t('Cancellation method'),
      '#access' => $selectCancel,
    ];

    $form['user_cancel_method'] += user_cancel_methods();

    if (!$selectCancel) {
      // Display an item to inform the user of the setting.       $default_method = $form['user_cancel_method']['#default_value'];
      $form['user_cancel_method_show'] = [
        '#type' => 'item',
        '#title' => $this->t('When cancelling these accounts'),
        '#plain_text' => $form['user_cancel_method']['#options'][$default_method],
      ];
    }

    
$form['registration_cancellation']['user_password_strength'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable password strength indicator'),
      '#default_value' => $config->get('password_strength'),
    ];
    $form['registration_cancellation']['user_cancel_method'] = [
      '#type' => 'radios',
      '#title' => $this->t('When cancelling a user account'),
      '#default_value' => $config->get('cancel_method'),
      '#description' => $this->t('Users with the %select-cancel-method or %administer-users <a href=":permissions-url">permissions</a> can override this default method.', ['%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), ':permissions-url' => Url::fromRoute('user.admin_permissions')->toString()]),
    ];
    $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
    foreach (Element::children($form['registration_cancellation']['user_cancel_method']) as $key) {
      // All account cancellation methods that specify #access cannot be       // configured as default method.       // @see hook_user_cancel_methods_alter()       if (isset($form['registration_cancellation']['user_cancel_method'][$key]['#access'])) {
        $form['registration_cancellation']['user_cancel_method'][$key]['#access'] = FALSE;
      }
    }

    // Default notifications address.     $form['mail_notification_address'] = [
      
Home | Imprint | This part of the site doesn't use cookies.