Verified Commit 33be9650 authored by Dave Long's avatar Dave Long
Browse files

task: #3607711 Deprecate \Drupal\Core\Htmx\Htmx methods

By: fathershawn
By: sourav_paul
By: quietone
By: macsim
By: godotislate
By: nicxvan
parent b265e035
Loading
Loading
Loading
Loading
Loading
+40 −2
Original line number Diff line number Diff line
@@ -496,9 +496,13 @@ public function triggerHeader(string|array $data): static {
   * @return static
   *   Self for chaining.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use \Drupal\Core\Htmx\Htmx::triggerHeader().
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/headers/hx-trigger/
   */
  public function triggerAfterSettleHeader(string|array $data): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    if (is_array($data)) {
      $data = json_encode($data);
    }
@@ -517,9 +521,13 @@ public function triggerAfterSettleHeader(string|array $data): static {
   * @return static
   *   Self for chaining.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *    use \Drupal\Core\Htmx\Htmx::triggerHeader().
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/headers/hx-trigger/
   */
  public function triggerAfterSwapHeader(string|array $data): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    if (is_array($data)) {
      $data = json_encode($data);
    }
@@ -933,9 +941,13 @@ public function disable(): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-disabled-elt/
   */
  public function disabledElt(string $descriptor): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-disabled-elt', $descriptor);
    return $this;
  }
@@ -952,9 +964,13 @@ public function disabledElt(string $descriptor): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-disinherit/
   */
  public function disinherit(string $names): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-disinherit', $names);
    return $this;
  }
@@ -989,9 +1005,13 @@ public function encoding(string $method = 'multipart/form-data'): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *  use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-ext/
   */
  public function ext(string $names): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-ext', $names);
    return $this;
  }
@@ -1027,9 +1047,13 @@ public function headers(array $headerValues): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-history/
   */
  public function history(): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-history', 'false');
    return $this;
  }
@@ -1042,7 +1066,6 @@ public function history(): static {
   *
   * @return static
   *   Returns this object to allow chaining methods.
   *   Returns this object to allow chaining methods.
   *
   * @see https://htmx.org/attributes/hx-history-elt/
   */
@@ -1111,9 +1134,13 @@ public function indicator(string $selector): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-inherit/
   */
  public function inherit(string $attributes): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-inherit', $attributes);
    return $this;
  }
@@ -1131,7 +1158,6 @@ public function inherit(string $attributes): static {
   *   the first name with `not`, as in ['not param1', 'param2', 'param3'].
   * - To only submit some parameters, use an array of parameter names as in
   *   ['param1', 'param2', 'param3'].
   * parameters use an array, pre
   *
   * @param string|string[] $filter
   *   The filter string or strings.
@@ -1139,9 +1165,13 @@ public function inherit(string $attributes): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-params/
   */
  public function params(string|array $filter): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    if (is_array($filter)) {
      $filter = implode(',', $filter);
    }
@@ -1178,9 +1208,13 @@ public function preserve(): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-prompt/
   */
  public function prompt(string $message): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createStringAttribute('hx-prompt', $message);
    return $this;
  }
@@ -1235,9 +1269,13 @@ public function replaceUrl(bool|Url $value): static {
   * @return static
   *   Returns this object to allow chaining methods.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead,
   *   use the approach given in the change record.
   * @see https://www.drupal.org/node/3583674
   * @see https://htmx.org/attributes/hx-request/
   */
  public function request(array $configValues): static {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. The corresponding attribute is removed from htmx v.4. An alternate approach is available and outlined in the change record. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    $this->createJsonAttribute('hx-request', $configValues);
    return $this;
  }
+10 −0
Original line number Diff line number Diff line
@@ -64,8 +64,13 @@ protected function isHtmxHistoryRestoration(): bool {
   *
   * @return string
   *   The value of the 'HX-Prompt' header, or an empty string if not set.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is
   *   no replacement.
   * @see https://www.drupal.org/node/3583674
   */
  protected function getHtmxPrompt(): string {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    return $this->getRequest()->headers->get('HX-Prompt', '');
  }

@@ -84,8 +89,13 @@ protected function getHtmxTarget(): string {
   *
   * @return string
   *   The value of the 'HX-Trigger' header, or an empty string if not set.
   *
   * @deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is
   *   no replacement.
   * @see https://www.drupal.org/node/3583674
   */
  protected function getHtmxTrigger(): string {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3583674', E_USER_DEPRECATED);
    return $this->getRequest()->headers->get('HX-Trigger', '');
  }

+17 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;

/**
 * Test all attribute-related Htmx public methods.
@@ -196,8 +197,10 @@ public function testHxHeaders(): void {
  /**
   * Test request method.
   */
  #[IgnoreDeprecations]
  public function testHxRequest(): void {
    $values = ['timeout' => 100, 'credentials' => FALSE];
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\Htmx::request() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. The corresponding attribute is removed from htmx v.4. An alternate approach is available and outlined in the change record. See https://www.drupal.org/node/3583674');
    $this->htmx->request($values);
    $render = $this->apply();
    $this->assertTrue(isset($render['#attributes']['data-hx-request']));
@@ -258,8 +261,22 @@ public function testSwap(): void {
  /**
   * Test remaining methods.
   */
  #[IgnoreDeprecations]
  #[DataProvider('hxSimpleStringAttributesDataProvider')]
  public function testHxSimpleAttributes(string $method, null|string|array $value, string $attribute, string|bool $expected): void {
    $expected_deprecation_message = match ($method) {
      'disabledElt' => 'Drupal\Core\Htmx\Htmx::disabledElt() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'disinherit' => 'Drupal\Core\Htmx\Htmx::disinherit() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'ext' => 'Drupal\Core\Htmx\Htmx::ext() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'history' => 'Drupal\Core\Htmx\Htmx::history() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'inherit' => 'Drupal\Core\Htmx\Htmx::inherit() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'params' => 'Drupal\Core\Htmx\Htmx::params() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      'prompt' => 'Drupal\Core\Htmx\Htmx::prompt() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Instead, use the approach given in the change record. See https://www.drupal.org/node/3583674',
      default => NULL,
    };
    if ($expected_deprecation_message !== NULL) {
      $this->expectUserDeprecationMessage($expected_deprecation_message);
    }
    if (is_null($value)) {
      $this->htmx->$method();
    }
+9 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;

/**
 * Test all header-related Htmx public methods.
@@ -237,7 +238,9 @@ public function testTriggerHeaderComplex(): void {
  /**
   * Test trigger header with simple data.
   */
  #[IgnoreDeprecations]
  public function testTriggerAfterSettleHeader(): void {
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\Htmx::triggerAfterSettleHeader() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674');
    $this->htmx->triggerAfterSettleHeader('foo');
    $render = $this->apply();
    $this->assertTrue(isset($render['#attached']['http_header']));
@@ -251,7 +254,9 @@ public function testTriggerAfterSettleHeader(): void {
  /**
   * Test trigger after settle header is correctly set with provided parameters.
   */
  #[IgnoreDeprecations]
  public function testTriggerAfterSettleHeaderComplex(): void {
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\Htmx::triggerAfterSettleHeader() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674');
    $this->htmx->triggerAfterSettleHeader([
      'showMessage' => [
        'level' => 'info',
@@ -270,7 +275,9 @@ public function testTriggerAfterSettleHeaderComplex(): void {
  /**
   * Test trigger header with simple data.
   */
  #[IgnoreDeprecations]
  public function testTriggerAfterSwapHeader(): void {
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\Htmx::triggerAfterSwapHeader() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674');
    $this->htmx->triggerAfterSwapHeader('foo');
    $render = $this->apply();
    $this->assertTrue(isset($render['#attached']['http_header']));
@@ -284,7 +291,9 @@ public function testTriggerAfterSwapHeader(): void {
  /**
   * Test trigger after settle header is correctly set with provided parameters.
   */
  #[IgnoreDeprecations]
  public function testTriggerAfterSwapHeaderComplex(): void {
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\Htmx::triggerAfterSwapHeader() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use ::triggerHeader() instead. See https://www.drupal.org/node/3583674');
    $this->htmx->triggerAfterSwapHeader([
      'showMessage' => [
        'level' => 'info',
+5 −8
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use Symfony\Component\HttpFoundation\Request;

/**
@@ -83,13 +84,11 @@ public function testIsHtmxHistoryRestoration(): void {
  /**
   * Tests the getHtmxPrompt method.
   */
  #[IgnoreDeprecations]
  public function testGetHtmxPrompt(): void {
    // Test with the header not present.
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\HtmxRequestInfoTrait::getHtmxPrompt() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3583674');
    $this->assertEquals('', $this->getHtmxPrompt());

    // Test with the header present.
    $this->request->headers->set('HX-Prompt', 'Enter a value');
    $this->assertEquals('Enter a value', $this->getHtmxPrompt());
  }

  /**
@@ -107,13 +106,11 @@ public function testGetHtmxTarget(): void {
  /**
   * Tests the getHtmxTrigger method.
   */
  #[IgnoreDeprecations]
  public function testGetHtmxTrigger(): void {
    // Test with the header not present.
    $this->expectUserDeprecationMessage('Drupal\Core\Htmx\HtmxRequestInfoTrait::getHtmxTrigger() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3583674');
    $this->assertEquals('', $this->getHtmxTrigger());

    // Test with the header present.
    $this->request->headers->set('HX-Trigger', 'submit-button');
    $this->assertEquals('submit-button', $this->getHtmxTrigger());
  }

  /**