1. Create a custom timezone detector

You can create and add your own timezone detector.

1.1. Create the detector class

Todo:
  • add example class called MyCustomTimezoneDetector

1.2. Add the Service

Create a service with the sonata_intl.timezone_detector tag with a custom alias.

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # config/services.yaml
    
    services:
        app.my_custom_timezone_detector:
            class: App\TimezoneDetector\MyCustomTimezoneDetector
            tags:
                - { name: sonata_intl.timezone_detector }
    
  • XML
    1
    2
    3
    4
    5
    <!-- config/services.xml -->
    
    <service id="app.my_custom_timezone_detector" class="App\TimezoneDetector\MyCustomTimezoneDetector">
        <tag name="sonata_intl.timezone_detector"/>
    </service>
    

1.3. Add the detector to the Configuration

You can now use this class by configuring the detector section:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    8
    # config/packages/sonata_intl.yaml
    
    sonata_intl:
        timezone:
            detectors:
                - app.my_custom_timezone_detector
                - sonata.intl.timezone_detector.user
                - sonata.intl.timezone_detector.locale
    

Important

In order to guess the timezone, the detectors will be called in the order they are declared.