Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-28351

Incorrect values from own bundle siteaccess aware configuration

    Details

    • Sprint:
      [2.2] Sprint 3

      Description

      When you try to expose siteaccess aware configuration for you bundle, accordingly to: https://doc.ezplatform.com/en/latest/cookbook/exposing_siteaccess_aware_configuration_for_your_bundle/ then you will get wrong default values when

      1. You didn't define key for possible array of values per siteaccess (in my example it is include_content_types)
      2. You didn't define any key and left only siteaccess name in configuration file

      Steps to reproduce

      1. Create your own bundle
      2. Create Configuration, e.g.: https://gist.github.com/kmadejski/f8480e3e97864c6b3b82b295dde85deb
      3. Create Extension, e.g.: https://gist.github.com/kmadejski/0786780fadf47afcabf459406a8371a9
      4. Create proper entry in config.yml, e.g.: https://gist.github.com/kmadejski/01ddac794bee34fb2e788f3d5cc60e6d
      5. Try to use configuration values in controller (or somewhere else, doesn't matter where), e.g.: https://gist.github.com/kmadejski/316f169429a5ae790d6ffb79bfe6e156

      Current results:

      Result without setting siteaccess name explicitly

      array (size=2)
        0 => 
          array (size=1)
            0 => string 'default' (length=7)
        1 => string 'default' (length=7)
      

      Result for eng siteaccess

      array (size=2)
        0 => 
          array (size=1)
            0 => string 'default' (length=7)
        1 => string 'default' (length=7)
      

      Result for nor siteaccess

      array (size=2)
        0 => 
          array (size=0)
            empty
        1 => string 'nor' (length=3)
      

      Result for pol siteaccess

      array (size=2)
        0 => 
          array (size=2)
            0 => string 'pol1' (length=4)
            1 => string 'pol2' (length=4)
        1 => string 'default' (length=7)
      

      Result for ger siteaccess

      array (size=2)
        0 => 
          array (size=0)
            empty
        1 => string 'default' (length=7)
      

      Expected results:
      Current results for getting parameters without indicating siteaccess name directly and eng and pol siteaccesses are correct.
      These for nor and ger siteaccesses are incorrect, see expected results below:

      Result for nor siteaccess

      array (size=2)
        0 => 
          array (size=1)
            0 => string 'default' (length=7)
        1 => string 'nor' (length=3)
      

      Result for ger siteaccess

      array (size=2)
        0 => 
          array (size=1)
            0 => string 'default' (length=7)
        1 => string 'default' (length=7)
      

        Activity

        Hide
        Andrzej Longosz added a comment -

        Kamil Madejski: The root cause of the issue is the way Symfony Configuration Processor processes scalar and array nodes.

        For the scalar node it's simple - no value - key is not added. However array node via ArrayNodeDefinition defines default value for missing setting, which is an empty array.

        As a result of that mapSettings maps an empty array as an actual setting.

        There's no way to distinguish if this empty array is a result of Symfony Processor normalization or if it's an intended setting.

        I see two possible solutions:

        1. For such complex settings, like arrays, please use mapConfigArray instead of mapSetting, as stated in the doc. Unlike mapSetting, mapConfigArray merges settings between scopes, so you'll be able to achieve desired result.

        In the given example it should be changed here to

        $processor->mapConfigArray('include_content_types', $config, ContextualizerInterface::UNIQUE);
        

        Keep in mind that for pol SiteAccess it will result in a merged array.

        ['default', 'pol1', 'pol2']
        

        2. If you want to override setting instead of merging it, you actually need to use mapSetting as mapConfigArray does not support overriding.

        In that case you'll need to sanitize manually your $config array prior to calling mapSetting, by removing empty arrays. I've tried that. The code ain't pretty

        If you see some generic solution we can apply to processing SiteAccess-aware configuration, please add a feature request. At this point I don't, because, as mentioned, there's no way to distinguish a default value from the actual setting.

        I think that there might be another ways to customize Semantic Config for that specific array nodes, but still - it has to be done per case.

        I'm closing this issue as the solution 1. is implied in the linked doc.

        Show
        Andrzej Longosz added a comment - Kamil Madejski : The root cause of the issue is the way Symfony Configuration Processor processes scalar and array nodes. For the scalar node it's simple - no value - key is not added. However array node via ArrayNodeDefinition defines default value for missing setting, which is an empty array. As a result of that mapSettings maps an empty array as an actual setting. There's no way to distinguish if this empty array is a result of Symfony Processor normalization or if it's an intended setting. I see two possible solutions: 1. For such complex settings, like arrays, please use mapConfigArray instead of mapSetting , as stated in the doc . Unlike mapSetting , mapConfigArray merges settings between scopes, so you'll be able to achieve desired result. In the given example it should be changed here to $processor ->mapConfigArray( 'include_content_types' , $config , ContextualizerInterface::UNIQUE); Keep in mind that for pol SiteAccess it will result in a merged array. [ 'default' , 'pol1' , 'pol2' ] 2. If you want to override setting instead of merging it, you actually need to use mapSetting as mapConfigArray does not support overriding. In that case you'll need to sanitize manually your $config array prior to calling mapSetting , by removing empty arrays. I've tried that. The code ain't pretty If you see some generic solution we can apply to processing SiteAccess-aware configuration, please add a feature request. At this point I don't, because, as mentioned, there's no way to distinguish a default value from the actual setting. I think that there might be another ways to customize Semantic Config for that specific array nodes, but still - it has to be done per case. I'm closing this issue as the solution 1. is implied in the linked doc.

          People

          • Assignee:
            Unassigned
            Reporter:
            Kamil Madejski
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Agile