Skip to content

Commit

Permalink
Allow to configure skipped layout handles via DI type of `ShouldModif…
Browse files Browse the repository at this point in the history
…yOutput`
  • Loading branch information
jissereitsma committed Sep 22, 2023
1 parent c1f26f7 commit 5e5b835
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Allow to configure skipped layout handles via DI type of `ShouldModifyOutput`

### Fixed
- Field in admin is `cache_directory_path` instead of `cache_directory` #154

Expand Down
33 changes: 20 additions & 13 deletions Util/ShouldModifyOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ class ShouldModifyOutput
* @var Config
*/
private $config;


/**
* @var array
*/
private $skippedHandles = [];

/**
* @param Config $config
*/
public function __construct(
Config $config
Config $config,
array $skippedHandles = []
) {
$this->config = $config;
$this->skippedHandles = $skippedHandles;
}

/**
* @param LayoutInterface $layout
* @return bool
Expand All @@ -30,27 +37,27 @@ public function shouldModifyOutput(LayoutInterface $layout): bool
if (!$this->config->enabled()) {
return false;
}

$handles = $layout->getUpdate()->getHandles();
if (empty($handles)) {
return false;
}

foreach ($handles as $handle) {
if (strstr($handle, '_email_')) {
return false;
}
}

$skippedHandles = [
'webp_skip',
'nextgenimages_skip',
];

if (array_intersect($skippedHandles, $handles)) {

if (array_intersect($this->skippedHandles, $handles)) {
return false;
}

return true;
}

public function getSkippedHandles(): array
{
return $this->skippedHandles;
}
}
9 changes: 9 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
</argument>
</arguments>
</type>

<type name="Yireo\NextGenImages\Util\ShouldModifyOutput">
<arguments>
<argument name="skippedHandles" xsi:type="array">
<item name="webp_skip" xsi:type="string">webp_skip</item>
<item name="nextgenimages_skip" xsi:type="string">nextgenimages_skip</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 5e5b835

Please sign in to comment.