TestHtmxHooks.php

Same filename and directory in other branches
  1. 11.x core/modules/system/tests/modules/test_htmx/src/Hook/TestHtmxHooks.php

Namespace

Drupal\test_htmx\Hook

File

core/modules/system/tests/modules/test_htmx/src/Hook/TestHtmxHooks.php

View source
<?php

declare (strict_types=1);
namespace Drupal\test_htmx\Hook;

use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Hooks for the test_htmx module.
 */
class TestHtmxHooks {
  public function __construct(protected RouteMatchInterface $routeMatch) {
  }
  
  /**
   * Implements hook_preprocess_HOOK() for html.
   */
  public function boost(array &$variables) : void {
    if ($this->routeMatch
      ->getRouteName() === 'test_htmx.attachments.body') {
      $variables['#attached']['library'][] = 'core/drupal.htmx';
      $variables['attributes']['data-hx-boost'] = 'true';
    }
  }

}

Classes

Title Deprecated Summary
TestHtmxHooks Hooks for the test_htmx module.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.