-
-
Save romainbessugesmeusy/eeda0b09764ececb4c7eee49db1c2d36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\DataObject; | |
use Pimcore\Model\DataObject\PrintingColor; | |
use Pimcore\Model\Element\AdminStyle; | |
class PrintingColorAdminStyle extends AdminStyle | |
{ | |
public function __construct($element) | |
{ | |
parent::__construct($element); | |
if (!($element instanceof PrintingColor)) { | |
return; | |
} | |
/** @var $element PrintingColor */ | |
$rgb = $element->getRbgPreview(); | |
$filename = "printing_color_{$rgb->getHex(false, false)}.png"; | |
if (!file_exists(PIMCORE_ASSET_DIRECTORY . "/printing_colors")) { | |
mkdir(PIMCORE_ASSET_DIRECTORY . "/printing_colors"); | |
} | |
$path = PIMCORE_ASSET_DIRECTORY . "/printing_colors/$filename"; | |
if (!file_exists($path)) { | |
$im = imagecreatetruecolor(20, 20); | |
$bg = imagecolorallocate($im, $rgb->getR(), $rgb->getG(), $rgb->getB()); | |
imagefilledrectangle($im, 0, 0, 20, 20, $bg); | |
imagepng($im, $path); | |
imagedestroy($im); | |
} | |
$this->elementIcon = "/printing_colors/$filename"; | |
$this->elementIconClass = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment