Skip to content

Change the way the minify_exclude configurations can be used. #13687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/Magento/Store/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<merge_files>0</merge_files>
<minify_files>0</minify_files>
<minify_exclude>
/tiny_mce/
<tiny_mce>/tiny_mce/</tiny_mce>
</minify_exclude>
</js>
<css>
<minify_files>0</minify_files>
<minify_exclude>
/tiny_mce/
<tiny_mce>/tiny_mce/</tiny_mce>
</minify_exclude>
</css>
<image>
Expand Down
16 changes: 15 additions & 1 deletion lib/internal/Magento/Framework/View/Asset/Minification.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,26 @@ public function getExcludes($contentType)
if (!isset($this->configCache[self::XML_PATH_MINIFICATION_EXCLUDES][$contentType])) {
$this->configCache[self::XML_PATH_MINIFICATION_EXCLUDES][$contentType] = [];
$key = sprintf(self::XML_PATH_MINIFICATION_EXCLUDES, $contentType);
foreach (explode("\n", $this->scopeConfig->getValue($key, $this->scope)) as $exclude) {
$excludeValues = $this->getMinificationExcludeValues($key);
foreach ($excludeValues as $exclude) {
if (trim($exclude) != '') {
$this->configCache[self::XML_PATH_MINIFICATION_EXCLUDES][$contentType][] = trim($exclude);
}
}
}
return $this->configCache[self::XML_PATH_MINIFICATION_EXCLUDES][$contentType];
}

/**
* Get minification exclude values from configuration
*
* @param string $key
* @return string[]
*/
private function getMinificationExcludeValues($key)
{
$configValues = $this->scopeConfig->getValue($key, $this->scope) ?? [];
Copy link
Contributor

@arendarenko arendarenko Sep 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getValue returns string.
Why don't you exploding this string like it was in original implementation?
Looks like it's an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alexeya-ven

getValue doesn't always return a string, the return value is being defined as mixed

In this case it returns an array instead of a string, because an extra level of nodes was added in the xml tree. So it's no longer a long string which could consist of multiple lines. But zero, one or multiple xml nodes instead.
By then using array_values, I'm getting the contents of those xml nodes which gives us an array of strings again, like the initial implementation did (which used explode).

The idea was to make this configuration mergeable so you can add multiple exclusions from different modules, which wasn't possible before, one module overwrote the configuration of another module.

I hope this makes it a bit more clear?


return array_values($configValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ public function testGetExcludes()
->expects($this->once())
->method('getValue')
->with('dev/js/minify_exclude')
->willReturn(
" /tiny_mce/ \n" .
" /tiny_mce2/ "
);
->willReturn([
'tiny_mce' => '/tiny_mce/',
'some_other_unique_name' => '/tiny_mce2/'
]);

$expected = ['/tiny_mce/', '/tiny_mce2/'];
$this->assertEquals($expected, $this->minification->getExcludes('js'));
Expand Down