Skip to content

Commit

Permalink
MAGETWO-83067: Save background color correctly in images. [backport 2…
Browse files Browse the repository at this point in the history
….1] #11890

 - Merge Pull Request #11890 from raumatbel/magento2:FR#BackgroundImage21
 - Merged commits:
   1. c9786df
   2. ea1fcf1
   3. d133c1d
  • Loading branch information
ishakhsuvarov committed Nov 3, 2017
2 parents 476a1e9 + d133c1d commit c6a96b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Catalog/Model/ImageExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
namespace Magento\Catalog\Model;

use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter;
use Magento\Catalog\Helper\Image;
use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter;
use Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface;

class ImageExtractor implements \Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface
class ImageExtractor implements TypeDataExtractorInterface
{
/**
* Extract configuration data of images from the DOM structure
Expand All @@ -30,8 +31,11 @@ public function process(\DOMElement $mediaNode, $mediaParentTag)
if ($attribute->nodeType != XML_ELEMENT_NODE) {
continue;
}
if ($attribute->tagName == 'background') {
$attributeTagName = $attribute->tagName;
if ($attributeTagName === 'background') {
$nodeValue = $this->processImageBackground($attribute->nodeValue);
} elseif ($attributeTagName === 'width' || $attributeTagName === 'height') {
$nodeValue = intval($attribute->nodeValue);
} else {
$nodeValue = $attribute->nodeValue;
}
Expand All @@ -55,6 +59,7 @@ private function processImageBackground($backgroundString)
$backgroundArray = [];
if (preg_match($pattern, $backgroundString, $backgroundArray)) {
array_shift($backgroundArray);
$backgroundArray = array_map('intval', $backgroundArray);
}
return $backgroundArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp()
public function testProcess()
{
$expectedArray = include(__DIR__ . '/_files/converted_view.php');
$this->assertEquals($expectedArray, $this->model->process($this->getDomElement(), 'media'));
$this->assertSame($expectedArray, $this->model->process($this->getDomElement(), 'media'));
}

/**
Expand Down

0 comments on commit c6a96b0

Please sign in to comment.