New answers tagged

5

For access control on routes, you can write a service which implements AccessInterface. At its simplest, this is just a class placed in a module's src/Access folder with a single method public function access(AccountInterface $account), returning a flavour of AccessResult. Then you simply register your class in the module's services.yml, annotate the route ...


4

Where should I place this complex access control in a way that I can easily call it in several controllers and hooks? Is there a name for the kind of feature I'm going to program? The term/concept you're looking for is a Service: Drupal 8 introduces the concept of services to decouple reusable functionality and makes these services pluggable and ...


1

In my case, the '$result->_entity' was empty, so I had to get the value from the '$result->_object' : function YOUR_THEME_preprocess_views_view__YOUR_VIEW_ID(array &$variables): void { foreach ($variables['view']->result as $result) { $node = $result->_object->getEntity(); $title = $node->get('title')->getValue()[0]['value']; ...


1

Doing a bit of guessing here because your code snippet doesn't show where you've implemented this bit of code. However, just blanket sending a response in the middle of Drupal's runtime is probably always going to have some odd side effects. Symfony's routing system (which Drupal uses) provides a number of different layers at which you can get involved with ...


2

I don't know how comfortable you are with code. I would suggest writing an update hook in a custom module. Something like: MYMODULE_update_8100(&$sandbox) { // On the initial run, set up the update. if (empty($sandbox)) { // Get all user ids. $sandbox['items'] = \Drupal::entityQuery('user') ->accessCheck(FALSE) ->execute(); ...


0

This question depends on where you are trying to access this information. Dependency injection is the ideal way to call drupal services. Often what you can do is go to core ([webroot]/core/lib/core), and look at core.services.yml. Tons of services are used in this file, making it a great reference point. For instance you want the current user, so search ...


0

This took me so long to find. Account Settings -> Manage Display admin/config/people/accounts/display/teaser


0

You can implement template_preprocess_field() and alter the markup of the date field. function MY_THEME_preprocess_field(&$vars) { if ($vars['field_name'] === 'field_custom_date_field') { $date_format = 'short'; // You need to provide the machine name of the format you want. $timestamp = strtotime($vars['element']['#items']->value); $...


0

In Drupal 7 you can easily go with: global $user; $new_value = "somevalue"; module_load_include('inc', 'profile2', 'profile2.admin'); $profile2 = profile2_by_uid_load($user->uid, "main"); $profile2__wrapper = entity_metadata_wrapper('profile2', $profile2); $profile2__wrapper->field_ultimo_display->set($new_value); $profile2__wrapper->save();


0

This is the best way on Drupal 8, create a custom module with Controller and send a variable to Twig: $pictureUri = $user->user_picture->entity->getFileUri(); $style = \Drupal::entityTypeManager()->getStorage('image_style')->load('thumbnail'); $urlPicture = $style->buildUrl($pictureUri);


0

short version use "drush uli" longer version have a local install with known password, go to your cpannel -> phpMyAdmin change the password to the known one. - done


0

Yes, it runs only on cache clear. You have to implement the dynamic behavior inside of the controller. By extending the core user controller you can call the parent method in case the dynamic condition doesn't apply: class UserCustomController extends UserController { public function resetPass(Request $request, $uid, $timestamp, $hash) { if (!...) { ...


Top 50 recent answers are included