Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display of page snippet does not take TYPO3_USER_SETTINGS into account #577

Open
2 tasks done
sorenmalling opened this issue Jun 10, 2024 · 2 comments
Open
2 tasks done

Comments

@sorenmalling
Copy link

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

The YoastUtility method snippetPreviewEnabled

if ((bool)($GLOBALS['BE_USER']->uc['hideYoastInPageModule'] ?? false)) {

does not take the default value of the TYPO3_USER_SETTINGS hideYoastInPageModule into account and expect that snippet is enabled.

Please describe what you expected to happen and why.

I'd expect the utility to take the default value into account in the condition, so it first checko the uc of the user and fallback to the default value

        if ((bool)($GLOBALS['BE_USER']->uc['hideYoastInPageModule'] ?? !($GLOBALS['TYPO3_USER_SETTINGS']['hideYoastInPageModule']['columns']['default'])) {
            return false;
        }

And set a default value in ext_tables.php for backward compability

How can we reproduce this behavior?

  1. Set a default value for hideYoastInPageModule to true
  2. Set the UI of the User Settings reflect that value
  3. Find that the snippet is still shown, because it's not saved to the uc field, untill the user clicks save

Technical info

  • TYPO3 version: 12.4.5
  • Yoast SEO version: 9.0.3
@sorenmalling
Copy link
Author

To solve it, we implemented this with usage of the AfterUserLoggedInEvent:

<?php

namespace OwnVendorName\YoastSeo\EventListener;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Authentication\Event\AfterUserLoggedInEvent;

final class HideYoastPreviewByDefault
{
    public function __invoke(AfterUserLoggedInEvent $event): void
    {
        if (
            $event->getUser() instanceof BackendUserAuthentication
        ) {
            $settingSet = $event->getUser()->uc['hideYoastInPageModule'] ?? false;
            if ($settingSet === false) {
                $event->getUser()->uc['hideYoastInPageModule'] = true;
                $event->getUser()->writeUC();
            }
        }
    }
}

@RinyVT
Copy link
Collaborator

RinyVT commented Nov 23, 2024

Hi @sorenmalling,

Sorry to get back at you so late, I've been testing with these settings and it seems that if you set a default (true/1) on $GLOBALS['TYPO3_USER_SETTINGS']['columns']['hideYoastInPageModule'] it's not possible for a user to "uncheck" it and thus allow the snippet preview to render.

If you don't want the snippet preview to render at all, couldn't you fix this with the tsconfig setting?
https://docs.typo3.org/p/yoast-seo-for-typo3/yoast_seo/10.0/en-us/Configuration/SnippetPreview/Index.html#disable-snippet-preview-with-pagets

Or could you describe your use case when this would be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants