Skip to main content
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;
    }
  }
}

 

 

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

Search

Page Facebook