Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions Classes/Hooks/PageCalloutsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;

/**
* Show broken links in page module.
*
* Requirements:
* - sypets/page-callouts installed
* - extension configuration showPageCalloutBrokenLinksExist is 2
* or showPageCalloutBrokenLinksExist is 1 and user setting tx_brofix_showPageCalloutBrokenLinksExist is 1
*/
class PageCalloutsHook implements SingletonInterface
{
protected bool $showPageCalloutBrokenLinksExist = false;
protected int $showPageCalloutBrokenLinksExist = 1;

public function __construct(
protected BrokenLinkRepository $brokenLinkRepository,
ExtensionConfiguration $extensionConfiguration,
protected readonly UriBuilder $uriBuilder
) {
$extensionConfigurationArray = $extensionConfiguration->get('brofix');
$this->showPageCalloutBrokenLinksExist = (bool)($extensionConfigurationArray['showPageCalloutBrokenLinksExist'] ?? true);
$this->showPageCalloutBrokenLinksExist = (int)($extensionConfigurationArray['showPageCalloutBrokenLinksExist'] ?? 1);
}

/**
Expand All @@ -32,11 +40,28 @@ public function __construct(
*/
public function addMessages(array $pageInfo): array
{
// check extension configuration
if (!$this->showPageCalloutBrokenLinksExist) {
/** @var BackendUserAuthentication $beUser */
$beUser = $GLOBALS['BE_USER'];
if (!$beUser->isAdmin() && !$beUser->check('modules', 'web_brofix')) {
// no output in case the user does not have access to the "brofix" module
return [];
}

// check extension configuration:
// if 0: do not show
// if 1: only show if user setting is also true
// if 2 : always show
switch ($this->showPageCalloutBrokenLinksExist) {
case 0:
return [];
case 1:
if (((bool)($beUser->uc['tx_brofix_showPageCalloutBrokenLinksExist'] ?? true)) === false) {
// do not show broken links in page module
return [];
}
// case 2: continue
}

if (!$pageInfo) {
return [];
}
Expand All @@ -45,17 +70,6 @@ public function addMessages(array $pageInfo): array
return [];
}

/** @var BackendUserAuthentication $beUser */
$beUser = $GLOBALS['BE_USER'];
if (!$beUser->isAdmin() && !$beUser->check('modules', 'web_brofix')) {
// no output in case the user does not have access to the "brofix" module
return [];
}
// check user settings (default is 1)
if (((bool)($beUser->uc['tx_brofix_showPageCalloutBrokenLinksExist'] ?? true)) === false) {
return [];
}

$lang = $this->getLanguageService();

$count = $this->brokenLinkRepository->getLinkCountForPage($pageId);
Expand Down
5 changes: 3 additions & 2 deletions Configuration/TCA/Overrides/be_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;

$typo3Version = GeneralUtility::makeInstance(Typo3Version::class);

if ($typo3Version->getMajorVersion() >= 14) {
// directly access extension configuration so class does not need to be initialized
$showPageCalloutBrokenLinksExist = (int)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['showPageCalloutBrokenLinksExist'] ?? 1);
if ($showPageCalloutBrokenLinksExist === 1 && $typo3Version->getMajorVersion() >= 14) {
/**
* @see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/14.2/Deprecation-108843-ExtensionManagementUtilityAddFieldsToUserSettings.html
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
Feature - Make page callouts configurable
===========================================

*since verion 6.1.0*
*since verion 6.1.0, changed again in 8.0.1*

If `EXT:page_callouts <https://extensions.typo3.org/extension/page_callouts>`__
is installed, information is displayed in the page module, if broken links exists.

Since this has a small performance impact, is not really necessary if broken
links are fixed regularly etc., this is now configurable via:
links are fixed regularly.

* extension configuration: "Show message in page module if broken links exist on page" *[showPageCalloutBrokenLinksExist]* (default: on)
This is now configurable via:

* extension configuration: "Show message in page module if broken links exist
on page" *[showPageCalloutBrokenLinksExist]* (default: "depends on user settings")
* user settings: "Show message in page module if broken links exist on page"
*[tx_brofix_showPageCalloutBrokenLinksExist]* in tab "Broken links" (default: on)
*[tx_brofix_showPageCalloutBrokenLinksExist]* in tab "Broken links" (default: on),
only available if extension configuration showPageCalloutBrokenLinksExist is
set to "depends on user settings".

The information is **only** displayed if extension configuration is set to true,
the user settings is active and page_callouts is installed (and of course, if
broken links exist on that page).
The information is **only** displayed if extension configuration is set to "Always"
or "depends on user settings" and the user settings is active.
Additionally, page_callouts mubst be installed.

Migration
=========
Expand Down
2 changes: 1 addition & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ showUrlChecker = 0

### page module ###

# cat=page module; type=boolean;label=Show message in page module if broken links exist on page: Has small performance impact, requires the extension page_callouts, can be further configured in BE user settings
# cat=page module; type=options[Never=0, Depends on user settings=1, Always=2];label=Show message in page module if broken links exist on page: Has small performance impact, requires the extension page_callouts, can be further configured in BE user settings
showPageCalloutBrokenLinksExist = 1
10 changes: 8 additions & 2 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

$typo3Version = GeneralUtility::makeInstance(Typo3Version::class);

if ($typo3Version->getMajorVersion() < 14) {
/**
* is moved to Configuration/TCA/Overrides/be_users.php for TYPO3 >= v14
* @todo Remove here when support for TYPO3 v13 is dropped
*/
// directly access extension configuration so class does not need to be initialized
$showPageCalloutBrokenLinksExist = (int)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['brofix']['showPageCalloutBrokenLinksExist'] ?? 1);
if ($showPageCalloutBrokenLinksExist === 1 && $typo3Version->getMajorVersion() < 14) {
// BE user settings
// ----------------

Expand All @@ -17,7 +23,7 @@
$GLOBALS['TYPO3_USER_SETTINGS']['columns']['tx_brofix_showPageCalloutBrokenLinksExist'] = [
'label' => $lll . ':usersettings.pagemodule.showPageCalloutBrokenLinksExist',
'type' => 'check',
'default' => '0',
'default' => '1',
];
ExtensionManagementUtility::addFieldsToUserSettings(
'--div--;' . $lll . ':usersettings.brofix.tab,tx_brofix_showPageCalloutBrokenLinksExist',
Expand Down
Loading