Using redirects with $response->send() like this used to work:
$response = new RedirectResponse($url);
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 ...
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',
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.
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. ...
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 ...
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&...