winter icon indicating copy to clipboard operation
winter copied to clipboard

Static Pages 2.0.2 on Winter 1.2.0 - Unable to add global "this" as the runtime or the extensions have already been initialized.

Open az-vm opened this issue 2 years ago • 11 comments

Winter CMS Build

1.2

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

Winter.Pages, Winter.Translate

Issue description

Hello,

First i want to thank you all for the great work done so far.

I was thinking to move to the new version of winter (1.2.0) and i done a fresh install of winter and plugins and copy my theme used on the version 1.1.9 to the theme folder.

And when i stay on the default language set, there is no problems, when i change to other locale, i got this error:

Unable to add global "this" as the runtime or the extensions have already been initialized. /Applications/MAMP/htdocs/winter_1_2/vendor/twig/twig/src/Environment.php line 766

Event Log:

LogicException: Unable to add global "this" as the runtime or the extensions have already been initialized. in /Applications/MAMP/htdocs/winter_1_2/vendor/twig/twig/src/Environment.php:766
Stack trace:
#0 /Applications/MAMP/htdocs/winter_1_2/modules/cms/Classes/Controller.php(316): Twig\Environment->addGlobal('this', Array)
#1 /Applications/MAMP/htdocs/winter_1_2/modules/cms/Classes/Controller.php(217): Cms\Classes\Controller->runPage(Object(Cms\Classes\Page))
#2 /Applications/MAMP/htdocs/winter_1_2/modules/cms/Classes/CmsController.php(50): Cms\Classes\Controller->run('/')
#3 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Cms\Classes\CmsController->run('/')
#4 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('run', Array)
#5 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Cms\Classes\CmsController), 'run')
#6 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()
#7 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(725): Illuminate\Routing\Route->run()
#8 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#9 /Applications/MAMP/htdocs/winter_1_2/plugins/winter/translate/classes/LocaleMiddleware.php(29): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#10 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Translate\Classes\LocaleMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#11 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#14 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#15 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#16 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#17 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#18 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#20 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#21 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#22 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#24 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(703): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#25 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(667): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#26 /Applications/MAMP/htdocs/winter_1_2/vendor/winter/storm/src/Router/CoreRouter.php(20): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#27 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Winter\Storm\Router\CoreRouter->dispatch(Object(Illuminate\Http\Request))
#28 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#29 /Applications/MAMP/htdocs/winter_1_2/plugins/offline/responsiveimages/classes/ResponsiveImagesMiddleware.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#30 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): OFFLINE\ResponsiveImages\Classes\ResponsiveImagesMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 /Applications/MAMP/htdocs/winter_1_2/vendor/winter/storm/src/Foundation/Http/Middleware/CheckForMaintenanceMode.php(25): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /Applications/MAMP/htdocs/winter_1_2/vendor/winter/storm/src/Foundation/Http/Middleware/CheckForTrustedProxies.php(56): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Foundation\Http\Middleware\CheckForTrustedProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /Applications/MAMP/htdocs/winter_1_2/vendor/winter/storm/src/Http/Middleware/TrustHosts.php(46): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Http\Middleware\TrustHosts->handle(Object(Illuminate\Http\Request), Object(Closure))
#38 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#39 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#40 /Applications/MAMP/htdocs/winter_1_2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#41 /Applications/MAMP/htdocs/winter_1_2/index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#42 {main}

Any one with this error ?

Thank You!

Steps to replicate

Change from default language for example -> from EN -> DE language.

Workaround

No response

az-vm avatar Aug 05 '22 15:08 az-vm

How are you changing the language? Changing the language to FR on https://spatialmedia.ca/fr doesn't trigger the issue.

LukeTowers avatar Aug 10 '22 00:08 LukeTowers

Hello @LukeTowers

This trigger is shown when i move my existing theme with all is content and layouts.

If i delete all the static pages on the theme, and create new content, the issue stops.

I have a big website will a lot of pages, and mv de theme and all is content of the static pages were nice.

Do you want me to publish online so you can check it ?

Kind Regards

az-vm avatar Aug 10 '22 10:08 az-vm

@az-vm yes please, we'll need to see it to check what's triggering the issue in your case.

LukeTowers avatar Aug 11 '22 16:08 LukeTowers

I don't see the error on any of the pages, what triggers it?

LukeTowers avatar Aug 11 '22 17:08 LukeTowers

I don't see the error on any of the pages, what triggers it?

  • Go to the language selector and change the language.

az-vm avatar Aug 11 '22 21:08 az-vm

Hello @LukeTowers

Did you have look at my email ?

az-vm avatar Sep 05 '22 17:09 az-vm

i have the same issue if i had an twig-put in my code:

== {% put intro %} Some random text {% endput %} ==

"intro" is a placeholder, I need in my layouts

Kuse-GmbH avatar Sep 14 '22 13:09 Kuse-GmbH

@az-vm I have not had a chance to yet, no.

@Kuse-GmbH why are you putting Twig inside of two == section separators?

LukeTowers avatar Sep 14 '22 15:09 LukeTowers

my layout contains this code:

 {% if placeholder('intro') %}
            <div class="intro hidden">
                {% placeholder intro title="Vorspann" %}
            </div>
        {% endif %}

if I save a static page, its generate a code like

[viewBag]
title = "Car Purchase"
meta_title = "Car Purchase"
meta_description = "Your automobile expert for high-quality automobiles in Munich. You want to sell your car? We are the right contact for the service around the used car sale"
top_heading = "Professional purchase of antique cars - we buy your antique car!"
top_text = "<p>You are looking for an expert when it comes to professional car purchase, and you'd like to sell your antique car? Come to Mirbach and Schuttenbach! We will provide expert advice and a fair quote - no strings attached. Our expert team for cars is always reliable - your satisfaction is our goal.</p>

<p>Mirbach Automobiles - that is quality antique cars and individual and expert advice. Your advantages with a purchase of your antique or classic car with Mirbach will be an efficient and quick handling, individual advice and a fair price. </p>"
services_textboxes[0][heading] = "Your advantages when selling your car to Mirbach near Munich:"
services_textboxes[0][image] = "/autohaus/schuttenbach-mirbach-beratung-kfz-kaufen_2_1500.jpg"
services_textboxes[0][subheading] = ""
services_textboxes[0][text] = "<ul>
	<li>Quick and efficient handling</li>
	<li>
Savings in time and cost</li>
	<li>
No need for advertisements or phone calls</li>
	<li>
Decent offers</li>
	<li>Expert advice</li>
	<li>Individual solutions</li>
</ul>"
services_textboxes[0][linktext] = ""
services_textboxes[0][url] = ""
services_textboxes[0][is_blank] = 0
breaker_heading = "Mirbach Cars: We buy your used car"
bottom_heading = "Selling your used car at Mirbach Cars in Anzing (Munich)"
bottom_text = "<p>You are thinking about selling your antique car? Mirbach is interested in purchasing your antique car. Our team of experts will examine and value your car and will present you a decent offer for it - no strings attached. We set great value on transparency when purchasing a car. That means that we will be able to explain to you in detail how the price comes off.</p>

<p>Quality cars come at a price. That is why we make fair offers - reflecting the real value of the antique car. You can be sure that we pursue the many years of maintenance and care that you invested into your beloved car. We will be happy to give advice if you want to sell your antique car. Just give us a call or pass by in Anzing near Munich. </p>"
==
{% put intro %}
<h2>Vehicle purchase</h2>

<p>You want to sell Classic Cars or your new car? From us you will receive a fair offer for each vehicle and we guarantee a serious transaction.</p>
{% endput %}
==

if it helps I can post the complete layout-file

BTW: in october 1 there was no problem with identical codes (over 2 jeahrs ago), I dont't know if this information helps

Kuse-GmbH avatar Sep 14 '22 16:09 Kuse-GmbH

@LukeTowers ok, but please check it up.

@Kuse-GmbH Thank you for the feedback.

Here is the thing:

I got this error using winter 1.2 when i try to change locale, but if i delete the static-page and add again with the same layout, the error does not occour.

With Octobercms dont have this problem with version 1, 2 or 3.

az-vm avatar Sep 14 '22 18:09 az-vm

some new infos: the problem also occurs on pages that are created in german only, as soon as you switch to english. it does not matter whether the english page exists or not.

the placeholder from my previous post doesn't seem to have any influence, as it also affects pages without placeholders.

EDIT: delete and recreate does not bring me any improvement

EDIT 2: in my case it was due to

'enableRoutesCache' => false,

in my dev-version of cms.php. when i call the page the first time, the error message comes up, after a refresh the page is working.

Wenn I clear the cache with the dashboard-widget in Romanov.ClearCacheWidget-Plugin, the error occurs one time, too (if that helps). After a php artisan cache:clear there is no error

EDIT 3: i currently assume it affects all pages of an additional language that are not yet cached/accessed for the first time

Kuse-GmbH avatar Sep 15 '22 09:09 Kuse-GmbH

Hello folks,

This issue is solve by the new versions of Winter Pages - 2.0.2, and Winter Translate - 2.1.0 , now all works fine on Winter CMS 1.2.1 with PHP 8.0 and 8.1.

Don´t upgrade on the backend, remove the older version and install it on composer, for now its the only way to update it.

So i will close this subject.

Thank you, az.vm

az-vm avatar Jan 12 '23 18:01 az-vm