<?php

/**
 * Class DataObjectPreviewer
 */
class DataObjectPreviewer
{
    /**
     * @param DataObjectPreviewInterface $record
     * @return string
     */
    public function preview(DataObjectPreviewInterface $record)
    {
        $content = $record->getPreviewHtml();
        $contentMd5 = md5($content);

        $htmlFilepath = sprintf(
            '%s/%s.html',
            DATAOBJECTPREVIEW_CACHE_PATH,
            $contentMd5
        );
        
        if (!file_exists(DATAOBJECTPREVIEW_CACHE_PATH)) {
            mkdir(DATAOBJECTPREVIEW_CACHE_PATH);
        }

        if (!file_exists($htmlFilepath)) {
            file_put_contents($htmlFilepath, $content);
        }

        return sprintf(
            '<div class="dataobjectpreview" data-src="%s"></div>',
            str_replace(BASE_PATH, '', $htmlFilepath)
        );
    }
}

<?php

/**
 * Class DataObjectPreviewer
 */
class DataObjectPreviewer
{
    /**
     * @param DataObjectPreviewInterface $record
     * @return string
     */
    public function preview(DataObjectPreviewInterface $record)
    {
        $content = $record->getPreviewHtml();
        $contentMd5 = md5($content);

        $htmlFilepath = sprintf(
            '%s/%s.html',
            DATAOBJECTPREVIEW_CACHE_PATH,
            $contentMd5
        );
        
        if (!file_exists(DATAOBJECTPREVIEW_CACHE_PATH)) {
            mkdir(DATAOBJECTPREVIEW_CACHE_PATH);
        }

        if (!file_exists($htmlFilepath)) {
            file_put_contents($htmlFilepath, $content);
        }

        return sprintf(
            '<div class="dataobjectpreview" data-src="%s"></div>',
            str_replace(BASE_PATH . '/', '', $htmlFilepath)
        );
    }
}

Use relative paths for previews to support sites in sub dirs
Use relative paths for previews to support sites in sub dirs

The use of an absolute path caused the dataobject previewer iframe to
point to an incorrect path when a site was not located directly in the
document root. A 404 page would display in all preview iframes instead
of the preview that had been rendered.
