Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Code snippet that can be used to set user status to blocked by default in drupal 8.

<?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if ($form_id == 'user_register_form'){
    if (isset($form['account']['status'])){
      $form['account']['status']['#default_value'] = 0;
      // by default default_value = 1
     // $form['account']['status']['#default_value'] = 1;
    }
  }
}

 

 

Comments

Submitted by firfin (not verified) on Tue, 03/08/2022 - 13:26 Permalink

This is the second time this week one of your snippets helped me out. Thanks a lot!
Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal and Laravel.

Web Posts

Search

Page Facebook