I'm creating my own EAV entity and one of the attributes of my entity has the type select so it requires a source model.
But I don't want to create my own class just for this attribute since I already have a virtual type defined for it that I use in the form and grid for a flat entity in the same module.

<virtualType name="SomeTypeNameHere" type="[Namespace]\[Module]\Model\Source\Options">
        <argument name="options" xsi:type="array">
            <item name="1" xsi:type="array">
                <item name="value" xsi:type="number">1</item>
                <item name="label" xsi:type="string" translate="true">Label 1</item>
            <item name="2" xsi:type="array">
                <item name="value" xsi:type="number">2</item>
                <item name="label" xsi:type="string" translate="true">Label 2</item>

Can I use SomeTypeNameHere as a source_model for an attribute ?
I know I can test this, but I'm far from having a functional entity. I'm still in the setup phase (more or less).
If someone already tried this I could use a simple Yes/No answer so I know which direction to take.


95% sure that it works.

If the Source Model is instantiated by the ObjectManager (I really think, or at least hope so, the Object Manager just creates a new Object of [Namespace]\[Module]\Model\Source\Options with the parameters defined for SomeTypeNameHere

  • Thanks for this. I will take this approach, with virtual types as source models, and if it does not work it's your fault :D.
    – Marius
    Jul 7 '16 at 13:18
  • all clear, I'm also curious ;) Jul 7 '16 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.