Sylius / Sylius/Stack

Use env vars to trigger hooks

Open
#266 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
PHP
Stars
45
Forks
34
PR merge metrics
No merged PRs in 30d

Description

I tried this syntax while creating a hook :

sylius_twig_hooks:
    hooks:
        'sylius_shop.base.header.top_bar':
            my_hook:
                template: '/shop/my_hook.html.twig'
                priority: 0
                enabled: '%env(bool:ENABLE_MY_HOOK)%'

The hook is always enabled, even if the env var ENABLE_MY_HOOK is false.

I tried also to define a parameter like this

parameters:
    app.enable_my_hook: '%env(bool:ENABLE_MY_HOOK)%'

And used it in the hook declaration :

sylius_twig_hooks:
    hooks:
        'sylius_shop.base.header.top_bar':
            my_hook:
                template: '/shop/my_hook.html.twig'
                priority: 0
                enabled: '%app.enable_my_hook%'

This feature flag worked when we used Sylius UI twig events in Sylius 1.x

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hook configuration from the issue with ENABLE_MY_HOOK set to false, then inspect the hook configuration handling to see why the enabled value is ignored. Confirm the behavior with both false and true environment values; done means the hook is disabled or enabled accordingly.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.