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

ContentDefender configuration in PageTSConfig #454

Open
599media opened this issue Oct 24, 2023 · 1 comment
Open

ContentDefender configuration in PageTSConfig #454

599media opened this issue Oct 24, 2023 · 1 comment

Comments

@599media
Copy link

Hi and thanks for the great work!

We're migrating some projects from ext:gridelements. As you might know gridelements has an integrated content_defender. The configuration there can be done via PageTSConfig and is therefor page-based (which is great for multi-site instances). In ext:container the content defender configuration can only be done via TCA and is therfor global if we're not mistaken.

Are there any plans on changing or extending this?

We did have a look at the getContentDefenderConfiguration-function in the Registry.php. It seems like the actual content_defender stuff is done on-the-fly. So you actually can access the PageTSConfig of the current page and are potentially able to override the global TCA-based content_defender configuration. Since we need this pretty badly, we are extending the class and try to implement this feature. Are you interested in pull request when we're done or is this something you don't see in ext:container?

@599media
Copy link
Author

599media commented Oct 7, 2024

Here is the extending class we use in our project to enable the mentioned behaviour... it basically checks if there's a PageTSConfig configuration for the content defender settings.

<?php

declare(strict_types=1);

namespace Fnn\FnnContainerExtended\Tca;

use TYPO3\CMS\Backend\Utility\BackendUtility;


class Registry extends \B13\Container\Tca\Registry
{
    public function getContentDefenderConfiguration(string $cType, int $colPos): array
    {
        $currentPageId = (int)$_GET['id'];
        $ctypeConfig = BackendUtility::getPagesTSconfig($currentPageId)['lib.']['fnnContainerExtended.'][$cType.'.'] ?? [];

        $contentDefenderConfiguration = [];
        $rows = $this->getGrid($cType);

        foreach ($rows as $columns) {
            foreach ($columns as $column) {
                if ((int)$column['colPos'] === $colPos) {
                    if (isset($column['allowed']) && !empty($column['allowed'])) {
                        $contentDefenderConfiguration['allowed.'] = $column['allowed'];
                    } else {
                        $contentDefenderConfiguration['allowed.'] = $ctypeConfig[$colPos.'.']['allowed.'] ?? [];
                    }

                    if (isset($column['disallowed']) && !empty($column['disallowed'])) {
                        $contentDefenderConfiguration['disallowed.'] = $column['disallowed'];
                    } else {
                        $contentDefenderConfiguration['disallowed.'] = $ctypeConfig[$colPos.'.']['disallowed.'] ?? [];
                    }

                    if (isset($column['maxitems']) && !is_null($column['maxitems'])) {
                        $contentDefenderConfiguration['maxitems'] = $column['maxitems'];
                    } else {
                        $contentDefenderConfiguration['maxitems'] = $ctypeConfig[$colPos.'.']['maxitems'] ?? 0;
                    }
                }
            }
        }

        return $contentDefenderConfiguration;
    }
}

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

No branches or pull requests

1 participant