-2

I need to access three constants from another file

here are my constants:

class ServiceOrderItemProcess implements LoaderInterface
{
    public const STATUS_PICKED_UP = 'soip.pcd';
    public const STATUS_DELIVERED = 'soip.dlv';
    public const STATUS_RETURNED = 'soip.rtn';
}

in my twig when I try to access them individually like this, it works.

{% if config.to != constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_PICKED_UP') %}

But I need to access all the three. Can anyone please help me? I think I need to create an array, but I don't know how do it.

I tried like this:

 {% if config.to != [constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_PICKED_UP'),
constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_RETURNED'),
constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_DELIVERED')] %}

It didn't return any error, but it din't access any of the constants either.

Edit: config.to contains all the statuses ("soip.pcd", "soip.pue", "soip.div", "soip.anf", "soip.hld", "soip.itrp", "soip.rfl", "soip.rtn", "soip.dlv", "soip.dmg").

They are all listed as constants in the class ServiceOrderItemProcess. The thing is, I need to access the three I mentioned.

  • 1
    What does `config.to` contain? Is that really an array, as in the second snippet? Or are you searching for something like `in_array` in Twig? – Nico Haase Feb 28 '23 at 13:12
  • config.to is exectally the statuses. Because I have 10 statuses in total, but I need to separate only these three I mentioned (soip.pcd, soip.dlv and soip.rtn) – Shirley Oliveira Feb 28 '23 at 13:16
  • 1
    Please add all clarification to your question by editing it. What have yout ried to resolve the problem? Does `config.to` contain all three constants? – Nico Haase Feb 28 '23 at 13:28
  • What happens if you dump the array of constants? Does it look as expected? If you dump `config.to` at the same location, do these arrays match? – Nico Haase Feb 28 '23 at 13:28
  • @NicoHaase thank you very much for trying to help, even though I didn't express myself very clearly. I managed to find the solution, it was something really silly. I edited again the question to show what I needed. – Shirley Oliveira Feb 28 '23 at 13:56
  • I'm glad you solved your problem. The convention here is that Answers are always separate from Questions, rather than being edited into the same text. You can add an Answer to your own Question in the box below if you think it will be useful to future readers. – IMSoP Feb 28 '23 at 14:02

1 Answers1

1

I found the solution.

 {% if config.to not in [
        constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_PICKED_UP'),
        constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_RETURNED'),
        constant('\\Uello\\Service\\StateMachine\\Loader\\ServiceOrderItemProcess::STATUS_DELIVERED')
    ] %}
  • 1
    If I were you I would look into [adding a custom filter](https://stackoverflow.com/questions/11907137/how-can-i-create-a-symfony-twig-filter) to solve this problem rather than using this (long) snippet – DarkBee Feb 28 '23 at 14:29