Pimcore\Model\Object\ClassDefinition\Data\Fieldcollections::getDiffVersionPreview PHP Method

getDiffVersionPreview() public method

Generates a pretty version preview (similar to getVersionPreview) can be either html or a image URL. See the ObjectMerger plugin documentation for details
public getDiffVersionPreview ( $data, null $object = null, mixed $params = [] ) : array | string
$data
$object null
$params mixed
return array | string
    public function getDiffVersionPreview($data, $object = null, $params = [])
    {
        $html = "";
        if ($data instanceof Object\Fieldcollection) {
            $html = "<table>";
            foreach ($data as $item) {
                if (!$item instanceof Object\Fieldcollection\Data\AbstractData) {
                    continue;
                }
                $type = $item->getType();
                $html .= "<tr><th><b>" . $type . "</b></th><th>&nbsp;</th><th>&nbsp;</th></tr>";
                try {
                    $collectionDef = Object\Fieldcollection\Definition::getByKey($item->getType());
                } catch (\Exception $e) {
                    continue;
                }
                $collectionData = [];
                foreach ($collectionDef->getFieldDefinitions() as $fd) {
                    $title = !empty($fd->title) ? $fd->title : $fd->getName();
                    $html .= "<tr><td>&nbsp;</td><td>" . $title . "</td><td>";
                    $html .= $fd->getVersionPreview($item->{$fd->getName()}, $object, $params);
                    $html .= "</td></tr>";
                }
            }
            $html .= "</table>";
        }
        $value = [];
        $value["html"] = $html;
        $value["type"] = "html";
        return $value;
    }