Change record status: 
Project: 
Introduced in branch: 
11.4.x
Introduced in version: 
11.4.0
Description: 

Before this change, hook_page_top and hook_page_bottom were the only way to inject content into the top and bottom of a page. Now it is possible to add this content directly from a Controller using the #attached key.

Before:

  /**
   * Implements hook_page_top().
   */
  #[Hook('page_top')]
  public function pageTop(array &$page_top): void {
    if ($this->routeMatch->getRouteName() == 'my_route') {
      $page_top['my_content'] = [
        '#markup' => '<p>Hello world</p>,
      ];
    }
  }

After:

// In the controller for my_route:
$build['#attached']['page_top']['my_module'] = [
  '#markup' => '<p>Hello world</p>,
];
Impacts: 
Module developers