Pimcore\Model\Object\ClassDefinition\Data\Hotspotimage::getDataFromResource PHP Method

getDataFromResource() public method

See also: Object\ClassDefinition\Data::getDataFromResource
public getDataFromResource ( Pimcore\Model\Object\Data\Hotspotimage $data, null | AbstractObject $object = null, mixed $params = [] ) : Asset
$data Pimcore\Model\Object\Data\Hotspotimage
$object null | Pimcore\Model\Object\AbstractObject
$params mixed
return Pimcore\Model\Asset
    public function getDataFromResource($data, $object = null, $params = [])
    {
        $imageId = $data[$this->getName() . "__image"];
        $image = Asset::getById($imageId);
        if ($image) {
            $metaData = $data[$this->getName() . "__hotspots"];
            // check if the data is JSON (backward compatibility)
            $md = json_decode($metaData, true);
            if (!$md) {
                $md = Serialize::unserialize($metaData);
            } else {
                if (is_array($md) && count($md)) {
                    $md["hotspots"] = $md;
                }
            }
            $hotspots = empty($md["hotspots"]) ? null : $md["hotspots"];
            $marker = empty($md["marker"]) ? null : $md["marker"];
            $crop = empty($md["crop"]) ? null : $md["crop"];
            $rewritePath = function ($data) {
                if (!is_array($data)) {
                    return [];
                }
                foreach ($data as &$element) {
                    if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) {
                        foreach ($element["data"] as &$metaData) {
                            // this is for backward compatibility (Array vs. MarkerHotspotItem)
                            if (is_array($metaData)) {
                                $metaData = new Element\Data\MarkerHotspotItem($metaData);
                            }
                        }
                    }
                }
                return $data;
            };
            $hotspots = $rewritePath($hotspots);
            $marker = $rewritePath($marker);
            $value = new Object\Data\Hotspotimage($imageId, $hotspots, $marker, $crop);
            return $value;
        }
        return null;
    }