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

Invalid type for path "contao.prepend_locale" #4161

Closed
fritzmg opened this issue Feb 18, 2022 · 18 comments · Fixed by #4437
Closed

Invalid type for path "contao.prepend_locale" #4161

fritzmg opened this issue Feb 18, 2022 · 18 comments · Fixed by #4437
Labels
Milestone

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Feb 18, 2022

Affected version(s)

4.13.0

Description

Our backwards compatibility to the old %prepend_locale% parameter does not seem to work anymore in newer Contao versions. i.e. if you have

parameters:
    prepend_locale: true

in your config/parameters.yaml, the following error will occur:

Symfony\Component\Config\Definition\Exception\InvalidTypeException:
Invalid type for path "contao.prepend_locale". Expected "bool", but got "string".
Hint: Whether or not to add the page language to the URL.

  at vendor\symfony\config\Definition\BooleanNode.php:29
  at Symfony\Component\Config\Definition\BooleanNode->validateType('%prepend_locale%')
     (vendor\symfony\config\Definition\BaseNode.php:564)
  at Symfony\Component\Config\Definition\BaseNode->doValidateType('%prepend_locale%')
     (vendor\symfony\config\Definition\BaseNode.php:407)
  at Symfony\Component\Config\Definition\BaseNode->normalize('%prepend_locale%')
     (vendor\symfony\config\Definition\ArrayNode.php:287)
  at Symfony\Component\Config\Definition\ArrayNode->normalizeValue(array('prepend_locale' => '%prepend_locale%'))
     (vendor\symfony\config\Definition\BaseNode.php:410)
  at Symfony\Component\Config\Definition\BaseNode->normalize(array('prepend_locale' => '%prepend_locale%'))
     (vendor\symfony\config\Definition\Processor.php:32)
  at Symfony\Component\Config\Definition\Processor->process(object(ArrayNode), array(array('preview_script' => '/preview.php'), array('legacy_routing' => false, 'localconfig' => array('licenseAccepted' => true, 'installPassword' => '…', 'adminEmail' => '…'), 'mailer' => …, array('prepend_locale' => '%prepend_locale%')))
     (vendor\symfony\config\Definition\Processor.php:46)
  at Symfony\Component\Config\Definition\Processor->processConfiguration …
@fritzmg fritzmg added this to the 4.13 milestone Feb 18, 2022
@aschempp
Copy link
Member

aschempp commented Feb 21, 2022

This looks like a Symfony/YAML bug if they read true as a string? Or maybe something changed in Symfony 5.4?

@fritzmg
Copy link
Contributor Author

fritzmg commented Feb 21, 2022

'%prepend_locale%' is a string though. I haven't looked into it yet, but it seems the parameter is not resolved anymore at that point.

@aschempp
Copy link
Member

We're only adding the parameter if it exists in the container (https://github.com/contao/contao/blob/5.x/manager-bundle/src/ContaoManager/Plugin.php#L262), so yeah maybe somehow Symfony does not load it anymore?

@rorych
Copy link
Contributor

rorych commented Mar 8, 2022

Is there any update here or is it currently not possible to use "prepend_locale" without changing to the new routing_mode?

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 8, 2022

@rorych just do the following:

# config/config.yaml
contao:
    prepend_locale: true

Using parameters.prepend_locale is deprecated.

@leofeyer
Copy link
Member

I cannot confirm this. I have added prepend_locale: true to my config file and run clear:cache afterwards. No exception.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 31, 2022

I cannot confirm this. I have added prepend_locale: true to my config file

Which one? config/config.yaml or config/parameters.yaml? This issue concerns the latter.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 31, 2022

I can still confirm the issue. Reproduction:

  1. Create a file called config/parameters.yaml
  2. Insert the following content:
    parameters:
        prepend_locale: true
  3. Execute the following command: rm -rf var && vendor/bin/contao-console cache:warmup

The following error will occur:

$ rm -rf var && vendor/bin/contao-console cache:warmup

In BooleanNode.php line 29:

  Invalid type for path "contao.prepend_locale". Expected "bool", but got "string".  
  Hint: Whether or not to add the page language to the URL.

@leofeyer
Copy link
Member

Ok, I can reproduce it now. Is there a way to fix this without changing ->booleanNode('prepend_locale')?

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 31, 2022

Changing the node would not be correct - for some reason the parameter ('%prepend_locale%') is not evaluated (or present?) when the config is evaluated by Symfony. So far I have not figured out why.

@aschempp
Copy link
Member

aschempp commented Apr 1, 2022

see #4437

@aschempp aschempp closed this as completed Apr 1, 2022
@leofeyer leofeyer linked a pull request Apr 1, 2022 that will close this issue
@christianromeni
Copy link
Contributor

btw.. same thing happens to pretty_error_screens
At least for me... But only if I use '%env(bool:PRETTY_ERROR)%' instead of true
I use env.local to set this parameter: PRETTY_ERROR=false

config.yaml

contao:
  pretty_error_screens: '%env(bool:PRETTY_ERROR)%'
  prepend_locale: true
  backend:
    attributes:
      app-name: 'xyz'
      app-version: '%env(VERSION)%'
    badge_title: '%env(BADGE_TITLE)%'

.env.local

APP_ENV="dev"
BADGE_TITLE='DEV'
PRETTY_ERROR=false

@aschempp
Copy link
Member

aschempp commented Apr 5, 2022

pretty sure thats fixed by #4437 as well, did you check that?

@christianromeni
Copy link
Contributor

christianromeni commented Apr 5, 2022

If that is in 4.13.2 then I don't think it's fixed..
If it is not released yet, I have not checked it... 🙈

@ausi
Copy link
Member

ausi commented Apr 5, 2022

#4437 was not released yet. You have to test 4.13.x-dev to see if the fix works for you.

@christianromeni
Copy link
Contributor

Ok, so I finally got the time to continue with my project, and it actually is still not working in Contao 4.13.4

Invalid type for path "contao.pretty_error_screens". Expected "bool", but got "string".
Hint: Show customizable, pretty error screens instead of the default PHP error messages.

Still the same config as mentioned in here

@fritzmg
Copy link
Contributor Author

fritzmg commented May 12, 2022

@christianromeni that's a different error message, referencing a completely different config. Please seek help in the Contao community.

@christianromeni
Copy link
Contributor

christianromeni commented May 12, 2022

@fritzmg Yes, because I disabled the setting for the composer update, so I could update to the latest version.. And check if it works..
This is the error I get in the frontend.. But during the installation, it was the error mentioned above.

In BooleanNode.php line 29:
                                                                               
  Invalid type for path "contao.pretty_error_screens". Expected "bool", but g  
  ot "string".                                                                 
  Hint: Show customizable, pretty error screens instead of the default PHP er  
  ror messages. 

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants