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

Replace $GLOBALS['objPage'] with the page finder #7014

Draft
wants to merge 1 commit into
base: 5.x
Choose a base branch
from

Conversation

leofeyer
Copy link
Member

@leofeyer leofeyer commented Mar 12, 2024

TODO

We sometimes override the global page object to replace insert tags, e.g. here:

// Override the global page object, so we can replace the insert tags
$GLOBALS['objPage'] = $page;
$title = implode(
'%s',
array_map(
static function ($strVal) {
return str_replace('%', '%%', System::getContainer()->get('contao.insert_tag.parser')->replaceInline($strVal));
},
explode('{{page::pageTitle}}', $layout->titleTag ?: '{{page::pageTitle}} - {{page::rootPageTitle}}', 2)
)
);
$GLOBALS['objPage'] = $origObjPage;

In these cases, we have to push a new request to the request stack instead.

@leofeyer leofeyer added this to the 5.4 milestone Mar 12, 2024
@leofeyer leofeyer self-assigned this Mar 12, 2024
@leofeyer leofeyer requested a review from a team March 12, 2024 22:13
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the two remaining places also used the PageFinder, we'd have a central place to adjust the code if we ever need to.

@@ -76,17 +76,6 @@ private function getPageModel(Request $request): PageModel|null

$pageModel = $request->attributes->get('pageModel');

if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also use the PageFinder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don‘t think so, because $pageModel can be an integer here, too. @aschempp /cc

$clientCache = 0;
$pageId = null;

$request = $this->requestStack->getCurrentRequest();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also use the PageFinder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service is not internal, so we cannot add a dependency. It also does not make sense to inject both the request stack and the page finder, because both provide the page model.

@leofeyer leofeyer marked this pull request as draft March 12, 2024 22:21
@leofeyer leofeyer changed the title Replace $GLOBALS['objPage'] in the non-legacy code Replace $GLOBALS['objPage'] with the page finder Mar 12, 2024
@leofeyer leofeyer force-pushed the feature/global-page branch 4 times, most recently from a16eb37 to ee40e51 Compare March 12, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants