New answers tagged

2

Since Drupal 8.5.x this works a little differently. Firstly it's good practice to set the timezone explicitly so you know what is going on: See PHP's list of supported timezones Get the default time zone using date_default_timezone_get(). Please note drupal_get_user_timezone() is deprecated since Drupal 8.8.0 and removed from Drupal 9.0.0. Use Drupal's ...


0

The field needs to be added to the search index here: /admin/config/search/search-api/index/YOUR_SEARCH_INDEX_NAME/fields Then the field shows up in the sort and filter sections in views.


1

You are almost have done it. I made a relationship between the content and the author. I can access field "x" in the fields part of views, but it does not show up in the "filter" or "order by" parts. add that fix "X" in sort section and sort it as Descending. when you make it descending contents with null values ...


1

What Drupal considers the default front page is not /node, but /user/login, which redirects logged-in users to their account page. SiteInformationForm::validateForm() contains the following code. // Check for empty front page path. if ($form_state->isValueEmpty('site_frontpage')) { // Set to default "user/login". $form_state->...


1

No you can't. The user.flood user_limit config setting feeds into the DatabaseBackend::isAllowed() method as the $threshold arg, which is used to compare the row count for this query: $number = $this->connection ->select(static::TABLE_NAME, 'f') ->condition('event', $name) ->condition('identifier', $identifier) ->...


0

Assuming the user rest resource is enabled and PATCH requests are configured, also that the requesting user is authenticated to update the user, then: send a PATCH request to: https://example.com/user/$uid?_format=json Where $uid is the user id to update (e.g 12) The request body should look something like this (json format): {
 "field_motherid":
 ...


1

Drupal uses code similar to the following one, to check if the user entered the wrong password too much times. // Don't allow login if the limit for this user has been reached. // Default is to allow 5 failed attempts every 6 hours. if (!$this->flood->isAllowed('user.failed_login_user', $flood_config->get('user_limit'), $flood_config->...


3

This is a configuration setting. You can run the drush command: drush cset user.flood user_limit 10


1

The error message doesn't specify which field caused the validation error. In this case, the error is caused by setting the init field with a value that isn't a valid email address. Differently from Drupal 7, in Drupal 8 the init field for the User entity is created using the email datatype. (See User::baseFieldDefinitions().) $fields['init'] = ...


-1

a User in drupal 8 becomes an entity type: and each entity type has storage class that enable us to CRUD a specific entity type entities, so in Drupal 8 in order to get a current user field we need to follow this steps : # step 1 : get current user ( an object represents the current user) $current_user = \Drupal::currentUser(); # step 2 : get the user ...


-1

Drupal 8 already uses PHP classes for entities. You don't use entity_metadata_wrapper() anymore. The code you need in Drupal 8 is the following. use Drupal\user\Entity\User; $account = User::load(\Drupal::currentUser()->id()); Alternatively, you could use the following code. $account = \Drupal::entityTypeManager()->getStorage('user')->load(\...


1

OK, this code seems to be the solution: /** * Implements hook_entity_field_access(). */ function MYMODULE_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL) { if ($field_definition->getName() == '...


1

The exceptions aren't caused from the code shown in the question. The second exception is caused from the following code in ContentEntityBase::getTranslatedField(). // Populate $this->fields to speed-up further look-ups and to keep track of // fields objects, possibly holding changes to field values. if (!isset($this->fields[$name][$langcode])) { $...


3

Simply scan the codebase for setLastLoginTime and you'll see that there's actually only one single place where this function gets called. And that is user_login_finalize. /** * Finalizes the login process and logs in a user. * * The function logs in the user, records a watchdog message about the new * session, saves the login timestamp, calls ...


1

If you want to first verify the user you programmatically created passes validation, which means (for example) that its username and emails are unique, you can check if there are validation violations. You don't need to fist call isValidationRequired() as that method returns the value set with setValidationRequired(), which is called only from ...


0

I ran into the same issue in some code today. The code was in a controller and the controller was mapped to a route for a URL which was being accessed by users from emails. The problem was that the URLs in the emails had http and the site was running on https. The site was also accessible via http and was not automatically redirecting to https. So when the ...


Top 50 recent answers are included