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

Craft CMS 4 update issues #58

Closed
mateostabio opened this issue Mar 24, 2023 · 3 comments
Closed

Craft CMS 4 update issues #58

mateostabio opened this issue Mar 24, 2023 · 3 comments

Comments

@mateostabio
Copy link

Hi, I've updated to Craft CMS 4 recently and started noticing this issue on a few pages on the en-us side.

Not sure exactly why it's throwing an internal server error:

TypeError: vaersaagod\geomate\helpers\GeoMateHelper::getCurrentLinkForSite(): Return value must be of type string|bool, null returned in /app/vendor/vaersaagod/geomate/src/helpers/GeoMateHelper.php:147

I'm not sure if it has to do with it, but on Craft CMS 3 my language toggle code worked perfectly.

{# logic #}
{% set currentElement = craft.app.urlManager.matchedElement %}
{% set sites = craft.app.getSites().getGroupById(currentSite.groupId).getSites() %}
{% set switcherLinks = [] %}

{% for site in sites if site.baseUrl is not empty %}

    {% set title = craft.app.i18n.getLocaleById(site.name) %}
    {% set url = site.getBaseUrl() %}
    {% if currentElement %}
        {% set otherLocaleElement = craft.app.getElements().getElementById(currentElement.id, currentElement.className(), site.id) %}
        {% if otherLocaleElement and otherLocaleElement.enabledForSite %}
            {% set url = otherLocaleElement.url %}
        {% endif %}
    {% endif %}

    {% set switcherLinks = switcherLinks|merge([{
        url: url, 
        title: site.name,
        current: site.id == currentSite.id ? true : false,
        language: site.language,
    }]) %}

But in Craft CMS 4, this was throwing an error due to {% for site in sites if site.baseUrl is not empty %}
So I changed this to:

{% for site in sites %}
{% if site.baseUrl is not empty %}

Any help is greatly appreciated.

@mmikkel
Copy link
Member

mmikkel commented Mar 24, 2023

Thanks for reporting that @mateostabio. That exception is due to a bug in GeoMate which is triggered by the stricter typing in PHP 8 – I'll get that fixed ASAP.

The exception will only happen when a site's baseUrl is null/empty, so to circumvent the issue until I can get this patched you might want to filter out any sites without URLs:

{% set sites = craft.app.getSites().getGroupById(currentSite.groupId).getSites() | filter(site => site.baseUrl is not empty) %}
...
{% for site in sites %}
...

...which is what the {% for site in sites if site.baseUrl is not empty %} conditional accomplished previously, but Twig has removed support for if statements within {% for %} tags in v. 3, which is what Craft 4 ships with.

@mateostabio
Copy link
Author

Thanks for the quick reply! But it's still throwing this error:

2023-03-24 12:40:56 [web.ERROR] [TypeError] vaersaagod\geomate\helpers\GeoMateHelper::getCurrentLinkForSite(): Return value must be of type string|bool, null returned {"trace":["#0 /app/vendor/vaersaagod/geomate/src/services/RedirectService.php(114): vaersaagod\geomate\helpers\GeoMateHelper::getCurrentLinkForSite(Object(craft\models\Site), true)","#1 /app/vendor/vaersaagod/geomate/src/services/RedirectService.php(43): vaersaagod\geomate\services\RedirectService->getRedirectInfo()","#2 /app/vendor/vaersaagod/geomate/src/GeoMate.php(179): vaersaagod\geomate\services\RedirectService->autoRedirect()","#3 /app/vendor/vaersaagod/geomate/src/GeoMate.php(127): vaersaagod\geomate\GeoMate->redirectCheck()","#4 [internal function]: vaersaagod\geomate\GeoMate->vaersaagod\geomate\{closure}(Object(yii\base\Event))","#5 /app/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Object(Closure), Object(yii\base\Event))","#6 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1560): yii\base\Component->trigger('init')","#7 /app/vendor/craftcms/cms/src/web/Application.php(106): craft\web\Application->_postInit()","#8 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()","#9 /app/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)","#10 [internal function]: yii\base\Application->__construct(Array)","#11 /app/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)","#12 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\web\\Appli...', Array, Array)","#13 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)","#14 /app/vendor/craftcms/cms/src/Craft.php(54): yii\BaseYii::createObject(Array, Array)","#15 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(252): Craft::createObject(Array)","#16 /app/vendor/craftcms/cms/bootstrap/web.php(40): require('/app/vendor/cra...')","#17 /app/web/index.php(11): require('/app/vendor/cra...')","#18 {main}"],"memory":8570400,"exception":"[object] (TypeError(code: 0): vaersaagod\geomate\helpers\GeoMateHelper::getCurrentLinkForSite(): Return value must be of type string|bool, null returned at /app/vendor/vaersaagod/geomate/src/helpers/GeoMateHelper.php:147)"}

@mmikkel
Copy link
Member

mmikkel commented Mar 24, 2023

Sorry, on further thought I guess that fix wouldn't have worked regardless as the issue was a return type conflict internally in GeoMate.

Should be fixed in GeoMate 2.1.1 though!

@mmikkel mmikkel closed this as completed Mar 24, 2023
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

2 participants