The user experience of the TYPO3 page module suffers as soon as you insert content elements with custom fields. The preview widgets all look like the same, hiding important information. How to solve this?
Motivation
As a developer for the Content Management System TYPO3, you usually customize and extend the system
for the particular use case of your stake holders. Giving their editors the best user experience
is a means to achieve acceptance and performance of managing content with TYPO3.
In the page module there are preview widgets for all content elements on the page.
The preview shows the header plus the value of the most important field for all default content elements.
For example, the image is the most important property for content elements of type “image”,
therefore it is rendered in the preview, together with the header:
When you create custom content elements, you have to tell TYPO3 how to render the preview widget.
By default only the standard fields from the core are rendered, depending on the “types” definition in TCA.
If you have custom fields which store the important information, the preview widget might look quite unintuitive.
Get this issue solved by hooking into the rendering process of the preview widget.
Unfortunately there is no clean-and-simple-API for that, but you can solve it with a hook and some PHP magic.
The rendering of the preview can be found in \TYPO3\CMS\Backend\View\PageLayoutView.
It provides a hook for customization. Your custom rendering definition has to implement the
interface \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface.
Thank you for this detailed description! Helped me a lot to create my own hook.
Alex
Thank you for writing this guide, it helped me figure out how to this after hours of searching. I just wish Typo3 would have more official documentation of this quality.
I had a problem while trying to implement this solution: I was getting a blank screen when clicking on a page in the backend (no preview whatsoever). The apache error logs said that the function declaration should exactly match the one in TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
So in this case it should be:
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$header, &$item, array &$row)
I hope this helps.
Steffen
Alex, thanks for your feedback. Since PHP7 checks for implementing interfaces are very strict.
Comments
Thank you for this detailed description! Helped me a lot to create my own hook.
Thank you for writing this guide, it helped me figure out how to this after hours of searching. I just wish Typo3 would have more official documentation of this quality.
I had a problem while trying to implement this solution: I was getting a blank screen when clicking on a page in the backend (no preview whatsoever). The apache error logs said that the function declaration should exactly match the one in
TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
So in this case it should be:
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$header, &$item, array &$row)
I hope this helps.
Alex, thanks for your feedback. Since PHP7 checks for implementing interfaces are very strict.