Loading core/lib/Drupal/Core/Htmx/Htmx.php +19 −4 Changes for core/lib/Drupal/Core/Htmx/Htmx.php: 19 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -1046,16 +1046,31 @@ public function vals(array $values, int $modifiers = self::NO_MODIFIER): static * form tags to use AJAX instead. This has the nice fallback that, if the * user does not have javascript enabled, the site will continue to work. * * @param bool $value * Should the element and its descendants be "boosted"? * The simple syntax is `hx-boost="true"` or `hx-boost="false"`. * * You can configure boost behavior using a config string that sets swap, * target, and other options directly on the hx-boost attribute. Set the * @code Htmx::INHERITED @endcode modifier to pass that config down to all * boosted descendants. * * The documentation link below has more information on the syntax and * precedence of the attributes between inherited and element attributes. * * @param bool|string $value * The value to be set for the attribute. * @param int $modifiers * The modifiers to apply to the attribute. Defaults to no modifiers. * * @return static * Returns this object to allow chaining methods. * * @see https://four.htmx.org/reference/attributes/hx-boost/ */ public function boost(bool $value = TRUE): static { $this->createStringAttribute('hx-boost', $value ? 'true' : 'false', self::NO_MODIFIER); public function boost(bool|string $value = TRUE, int $modifiers = self::NO_MODIFIER): static { if (is_bool($value)) { $value = $value ? 'true' : 'false'; } $this->createStringAttribute('hx-boost', $value, $modifiers); return $this; } Loading core/tests/Drupal/Tests/Core/Htmx/HtmxAttributesTest.php +16 −2 Changes for core/tests/Drupal/Tests/Core/Htmx/HtmxAttributesTest.php: 16 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -202,14 +202,28 @@ public function testHxVals(): void { /** * Test boost method. */ #[DataProvider('booleanStringDataProvider')] public function testHxBoost(bool $value, string $expected): void { #[DataProvider('boostStringDataProvider')] public function testHxBoost(bool|string $value, string $expected): void { $this->htmx->boost($value); $render = $this->apply(); $this->assertTrue(isset($render['#attributes']['data-hx-boost'])); $this->assertEquals($expected, $render['#attributes']['data-hx-boost']); } /** * Provides data to self::testHxBoost. * * @return array{bool|string, string}[] * First parameter is a boolean or string, second parameter is a string. */ public static function boostStringDataProvider(): array { return [ [TRUE, 'true'], [FALSE, 'false'], ['swap:outerSync select:#main target:#main', 'swap:outerSync select:#main target:#main'], ]; } /** * Test headers method. */ Loading Loading
core/lib/Drupal/Core/Htmx/Htmx.php +19 −4 Changes for core/lib/Drupal/Core/Htmx/Htmx.php: 19 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -1046,16 +1046,31 @@ public function vals(array $values, int $modifiers = self::NO_MODIFIER): static * form tags to use AJAX instead. This has the nice fallback that, if the * user does not have javascript enabled, the site will continue to work. * * @param bool $value * Should the element and its descendants be "boosted"? * The simple syntax is `hx-boost="true"` or `hx-boost="false"`. * * You can configure boost behavior using a config string that sets swap, * target, and other options directly on the hx-boost attribute. Set the * @code Htmx::INHERITED @endcode modifier to pass that config down to all * boosted descendants. * * The documentation link below has more information on the syntax and * precedence of the attributes between inherited and element attributes. * * @param bool|string $value * The value to be set for the attribute. * @param int $modifiers * The modifiers to apply to the attribute. Defaults to no modifiers. * * @return static * Returns this object to allow chaining methods. * * @see https://four.htmx.org/reference/attributes/hx-boost/ */ public function boost(bool $value = TRUE): static { $this->createStringAttribute('hx-boost', $value ? 'true' : 'false', self::NO_MODIFIER); public function boost(bool|string $value = TRUE, int $modifiers = self::NO_MODIFIER): static { if (is_bool($value)) { $value = $value ? 'true' : 'false'; } $this->createStringAttribute('hx-boost', $value, $modifiers); return $this; } Loading
core/tests/Drupal/Tests/Core/Htmx/HtmxAttributesTest.php +16 −2 Changes for core/tests/Drupal/Tests/Core/Htmx/HtmxAttributesTest.php: 16 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -202,14 +202,28 @@ public function testHxVals(): void { /** * Test boost method. */ #[DataProvider('booleanStringDataProvider')] public function testHxBoost(bool $value, string $expected): void { #[DataProvider('boostStringDataProvider')] public function testHxBoost(bool|string $value, string $expected): void { $this->htmx->boost($value); $render = $this->apply(); $this->assertTrue(isset($render['#attributes']['data-hx-boost'])); $this->assertEquals($expected, $render['#attributes']['data-hx-boost']); } /** * Provides data to self::testHxBoost. * * @return array{bool|string, string}[] * First parameter is a boolean or string, second parameter is a string. */ public static function boostStringDataProvider(): array { return [ [TRUE, 'true'], [FALSE, 'false'], ['swap:outerSync select:#main target:#main', 'swap:outerSync select:#main target:#main'], ]; } /** * Test headers method. */ Loading