sypets/page-callouts

Add callouts to page module in TYPO3 backend

Installs: 81

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:typo3-cms-extension

v1.0.2 2021-02-04 14:44 UTC

This package is not auto-updated.

Last update: 2021-04-02 12:10:00 UTC


README

Why this extension?

Informational, warning and error messages are displayed as "callouts" in the page module for various reasons, for example:

  • info message if page is of type folder
  • warning message if there are elements with an invalid colpos ("unused elements")
  • a page was defined as a shortcut, but has a missing target

However, it is not easily possible for extensions to add callouts of their own.

This extension provides a hook to add additional messages.

How it works

This extension Xclasses the PageLayoutController of the TYPO3 core. The class is inherited and the method getHeaderFlashMessagesForCurrentPid() overriden.

All functions which use the hook are called and the additional messages rendered.

How to use the hook

Simple example:

ext_localconf.php:

// ...
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Sypets/PageCallouts/Xclass/PageLayoutControllerWithMessages']['addFlashMessageToPageModule'][] =
    \Myvendor\MyExtension\Hooks\PageCalloutsHook::class;

ClassesHooksPageCalloutsHook.php:

<?php
declare(strict_types=1);
namespace Myvendor\MyExtension\Hooks;

use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;

final class PageCalloutsHook
{
    public function addMessages(array $pageInfo): array
    {
        $pageId = (int) ($pageInfo['uid']);

        if ($someCondition) {
            $title = 'Some title';
            $message = 'some message';
            return [
                'title' => $title,
                'message' => $message,
                'state' => InfoboxViewHelper::STATE_ERROR
            ];
        }
        return [];
    }
}