Skip to content

[2.2] Implement alternative fix for #12285:The option false for mobile device don't work in product view page gallery #17969

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

Closed
wants to merge 11 commits into from
Closed
21 changes: 20 additions & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public function getMagnifier()
*/
public function getBreakpoints()
{
return $this->jsonEncoder->encode($this->getVar('breakpoints'));
$breakpoints = $this->getVar('breakpoints');
array_walk_recursive($breakpoints, [$this, 'convertBooleans']);
return $this->jsonEncoder->encode($breakpoints);
}

/**
Expand Down Expand Up @@ -138,6 +140,23 @@ public function getGalleryImagesJson()
return json_encode($imagesItems);
}

/**
* Convert string to booleans
*
* @param string $item
* @param string $key
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected static function convertBooleans(&$item, $key)
{
if (strtolower($item) == 'true') {
$item = true;
}
if (strtolower($item) == 'false') {
$item = false;
}
}

/**
* Retrieve gallery url
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,29 @@
"options": {
"nav": "<?= $block->escapeHtml($block->getVar("gallery/nav")) ?>",
<?php if (($block->getVar("gallery/loop"))) : ?>
"loop": <?= $block->escapeHtml($block->getVar("gallery/loop")) ?>,
"loop": <?= /* @noEscape */
filter_var($block->getVar("gallery/loop"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/keyboard"))) : ?>
"keyboard": <?= $block->escapeHtml($block->getVar("gallery/keyboard")) ?>,
"keyboard": <?= /* @noEscape */
filter_var($block->getVar("gallery/keyboard"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/arrows"))) : ?>
"arrows": <?= $block->escapeHtml($block->getVar("gallery/arrows")) ?>,
"arrows": <?= /* @noEscape */
filter_var($block->getVar("gallery/arrows"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if (($block->getVar("gallery/allowfullscreen"))) : ?>
"allowfullscreen": <?= $block->escapeHtml($block->getVar("gallery/allowfullscreen")) ?>,
"allowfullscreen": <?= /* @noEscape */
filter_var($block->getVar("gallery/allowfullscreen"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if (is_bool($block->getVar("gallery/caption"))) : ?>
"showCaption": <?= /* @noEscape */ $block->getVar("gallery/caption") ? 'true' : 'false'; ?>,
<?php if ($block->getVar("gallery/caption")) : ?>
"showCaption": <?= /* @noEscape */
filter_var($block->getVar("gallery/caption"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php
$imgWidth = $block->getImageAttribute('product_page_image_medium', 'width');
Expand Down Expand Up @@ -88,27 +98,36 @@
<?php endif; ?>
"transition": "<?= $block->escapeHtml($block->getVar("gallery/transition/effect")) ?>",
<?php if (($block->getVar("gallery/navarrows"))) : ?>
"navarrows": <?= $block->escapeHtml($block->getVar("gallery/navarrows")) ?>,
"navarrows": <?= /* @noEscape */
filter_var($block->getVar("gallery/navarrows"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
"navtype": "<?= $block->escapeHtml($block->getVar("gallery/navtype")) ?>",
"navdir": "<?= $block->escapeHtml($block->getVar("gallery/navdir")) ?>"
},
"fullscreen": {
"nav": "<?= $block->escapeHtml($block->getVar("gallery/fullscreen/nav")) ?>",
<?php if ($block->getVar("gallery/fullscreen/loop")) : ?>
"loop": <?= $block->escapeHtml($block->getVar("gallery/fullscreen/loop")) ?>,
"loop": <?= /* @noEscape */
filter_var($block->getVar("gallery/fullscreen/loop"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
"navdir": "<?= $block->escapeHtml($block->getVar("gallery/fullscreen/navdir")) ?>",
<?php if ($block->getVar("gallery/transition/navarrows")) : ?>
"navarrows": <?= $block->escapeHtml($block->getVar("gallery/fullscreen/navarrows")) ?>,
<?php if ($block->getVar("gallery/fullscreen/navarrows")) : ?>
"navarrows": <?= /* @noEscape */
filter_var($block->getVar("gallery/fullscreen/navarrows"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
"navtype": "<?= $block->escapeHtml($block->getVar("gallery/fullscreen/navtype")) ?>",
<?php if ($block->getVar("gallery/fullscreen/arrows")) : ?>
"arrows": <?= $block->escapeHtml($block->getVar("gallery/fullscreen/arrows")) ?>,
"arrows": <?= /* @noEscape */
filter_var($block->getVar("gallery/fullscreen/arrows"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if (is_bool($block->getVar("gallery/fullscreen/caption"))) : ?>
<?php $showCaption = $block->getVar("gallery/fullscreen/caption") ? 'true' : 'false'; ?>
"showCaption": <?= /* @noEscape */ $showCaption ?>,
<?php if ($block->getVar("gallery/fullscreen/caption")) : ?>
"showCaption": <?= /* @noEscape */
filter_var($block->getVar("gallery/fullscreen/caption"), FILTER_VALIDATE_BOOLEAN)
? 'true' : 'false'; ?>,
<?php endif; ?>
<?php if ($block->getVar("gallery/fullscreen/transition/duration")) : ?>
"transitionduration": <?=
Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions lib/internal/Magento/Framework/Config/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ protected function parseVarElement(\DOMElement $node)
}
}
if (!count($result)) {
$result = (strtolower($node->nodeValue) !== 'true' && strtolower($node->nodeValue) !== 'false')
? $node->nodeValue
: filter_var($node->nodeValue, FILTER_VALIDATE_BOOLEAN);
$result = $node->nodeValue;
}
return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ protected function _getSidPlaceholder($cacheKey = null)
*
* @param string $name variable name
* @param string|null $module optional module name
* @return string|false
* @return string|false|array
*/
public function getVar($name, $module = null)
{
Expand Down