Skip to content
Snippets Groups Projects
Commit fa9e2b51 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2248969 by tstoeckler: Default the user status field to FALSE.

parent aedaf116
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -140,9 +140,9 @@ protected function getAutocompleteResult($type, $input) { ...@@ -140,9 +140,9 @@ protected function getAutocompleteResult($type, $input) {
*/ */
public function testBaseField() { public function testBaseField() {
// Add two users. // Add two users.
$user_1 = entity_create('user', array('name' => 'auto1')); $user_1 = entity_create('user', array('name' => 'auto1', 'status' => TRUE));
$user_1->save(); $user_1->save();
$user_2 = entity_create('user', array('name' => 'auto2')); $user_2 = entity_create('user', array('name' => 'auto2', 'status' => TRUE));
$user_2->save(); $user_2->save();
$request = Request::create('entity_reference/autocomplete/single/user_id/entity_test/entity_test/NULL'); $request = Request::create('entity_reference/autocomplete/single/user_id/entity_test/entity_test/NULL');
......
...@@ -504,10 +504,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ...@@ -504,10 +504,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['status'] = FieldDefinition::create('boolean') $fields['status'] = FieldDefinition::create('boolean')
->setLabel(t('User status')) ->setLabel(t('User status'))
->setDescription(t('Whether the user is active or blocked.')) ->setDescription(t('Whether the user is active or blocked.'))
// @todo As the status has access implications users should be created as ->setSetting('default_value', FALSE);
// blocked by default and activated explicitly if needed. See
// https://drupal.org/node/2248969.
->setSetting('default_value', TRUE);
$fields['created'] = FieldDefinition::create('created') $fields['created'] = FieldDefinition::create('created')
->setLabel(t('Created')) ->setLabel(t('Created'))
......
...@@ -29,6 +29,7 @@ public function __construct(EntityManagerInterface $entity_manager, LanguageMana ...@@ -29,6 +29,7 @@ public function __construct(EntityManagerInterface $entity_manager, LanguageMana
*/ */
public function form(array $form, array &$form_state) { public function form(array $form, array &$form_state) {
$user = $this->currentUser(); $user = $this->currentUser();
/** @var \Drupal\user\UserInterface $account */
$account = $this->entity; $account = $this->entity;
$admin = $user->hasPermission('administer users'); $admin = $user->hasPermission('administer users');
// Pass access information to the submit handler. Running an access check // Pass access information to the submit handler. Running an access check
...@@ -47,6 +48,14 @@ public function form(array $form, array &$form_state) { ...@@ -47,6 +48,14 @@ public function form(array $form, array &$form_state) {
$form['#attached']['library'][] = 'core/jquery.cookie'; $form['#attached']['library'][] = 'core/jquery.cookie';
$form['#attributes']['class'][] = 'user-info-from-cookie'; $form['#attributes']['class'][] = 'user-info-from-cookie';
// Because the user status has security implications, users are blocked by
// default when created programmatically and need to be actively activated
// if needed. When administrators create users from the user interface,
// however, we assume that they should be created as activated by default.
if ($admin) {
$account->activate();
}
// Start with the default user account fields. // Start with the default user account fields.
$form = parent::form($form, $form_state, $account); $form = parent::form($form, $form_state, $account);
......
...@@ -46,6 +46,7 @@ protected function createEntity() { ...@@ -46,6 +46,7 @@ protected function createEntity() {
// Create a "Llama" user. // Create a "Llama" user.
$user = entity_create('user', array( $user = entity_create('user', array(
'name' => 'Llama', 'name' => 'Llama',
'status' => TRUE,
)); ));
$user->save(); $user->save();
......
...@@ -84,6 +84,7 @@ function user_install() { ...@@ -84,6 +84,7 @@ function user_install() {
'uid' => 1, 'uid' => 1,
'name' => 'placeholder-for-uid-1', 'name' => 'placeholder-for-uid-1',
'mail' => 'placeholder-for-uid-1', 'mail' => 'placeholder-for-uid-1',
'status' => TRUE,
'langcode' => $langcode, 'langcode' => $langcode,
)) ))
->save(); ->save();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment