Hot answers tagged

3

Using redirects with $response->send() like this used to work: $response = new RedirectResponse($url); $response->send(); But, this no longer works in Drupal 9.2. Also, it breaks JSON:API in versions before 9.2. The correct way to do it is described in detail in this excellent answer. Basically, you need to create your own custom http_middleware ...


1

hook_entity_presave() and hook_ENTITY_TYPE_presave() should not assume the entity has been edited in a form, or a page has been shown to the users. Those hooks are also invoked when an entity is programmatically created, for example with the following code, which could also be used in a hook_cron() implementation. $values = [ 'type' => 'article', '...


1

Objective: Show upcoming events, then past events. The simplest way to implement this entirely through the View UI is to add a second display to the view. Basic steps Create the main view display. Configure the events to display as you like. Set to sort by upcoming events, and filter so that only upcoming events are displayed. Add an Attachment display. ...


1

hook_pathauto_pattern_alter() is only invoked when: The entity has a path field Pathauto processing is enabled For entities that support revisions, the entity is using the default revision A default pattern has been set for that entity $entity->toUrl()->getInternalPath() doesn't throw a EntityMalformedException, UndefinedLinkTemplateException, or ...


1

Per the Drupal coding standards, the closing php tag should be omitted. The PHP Code Tags section of the coding standards (as well as this stackoverflow answer) give a good overview of why it's a good practice to omit them in general: Removing it eliminates the possibility for unwanted whitespace at the end of files which can cause "header already sent&...


Only top voted, non community-wiki answers of a minimum length are eligible