By admin , 26 March, 2024 Get string link to user $attributes = [ 'title' => 'View user profile.', ]; $link = $test_user->toLink(NULL, 'canonical', ['attributes' => $attributes])->toString(); Tags user
By admin , 26 March, 2024 Get user (id) from URL $user = \Drupal::routeMatch()->getParameter('user'); Tags user routes
By admin , 26 March, 2024 Render BlockBase programmatically /** * Implements hook_ENTITY_TYPE_view(). */ function my_module_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { if ($display->getComponent('my_block')) { $block = \Drupal::service('plugin.manager.block')->createInstanc Tags block render
By admin , 26 March, 2024 Render views block programmatically /** * Implements hook_ENTITY_TYPE_view(). */ function my_module_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { if ($display->getComponent('my_module')) { $view = Views::getView('my_module_block'); Tags block views render
By admin , 11 March, 2024 If current user has permission \Drupal::currentUser()->hasPermission('my permission'); Tags permissions
By admin , 11 March, 2024 Add message to watchdog \Drupal::logger('my_module')->info('Info'); Tags watchdog logger
By admin , 29 February, 2024 Disable reaching a node by its internal path (node id) use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\node\NodeInterface; function MYMODULE_preprocess_page Tags access
By admin , 17 February, 2024 Form template: render field separately <form{{ attributes }}> <div class="wrapper d-flex"> <div class="left"> Tags twig form
By admin , 14 February, 2024 Uninstall module if stuck at 'Fields pending deletion' drush php-eval 'field_purge_batch(10000);' Tags drush field
By admin , 25 January, 2024 Inject user.data service use Drupal\user\UserDataInterface; /** * The user data service. */ protected UserDataInterface $userData; /** * Constructs the object. * * @param \Drupal\user\UserDataInterface $user_data * The user data service. */ public Tags service dependency injection