n Drupal 8 - Set user status to blocked by default | CodimTh

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

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


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;



Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

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

Web Posts


Page Facebook