Magento2 : Retrieve Multiselect Values in system.xml












1















I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?










share|improve this question

























  • I found the solution by using Mage::getStoreConfig(section_group_field path)

    – Eubie Aluad
    Oct 24 '17 at 9:41











  • bit.ly/2w7H6y2 using link got all the multiselect attribute.

    – Rakesh Jesadiya
    Aug 23 '18 at 17:41
















1















I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?










share|improve this question

























  • I found the solution by using Mage::getStoreConfig(section_group_field path)

    – Eubie Aluad
    Oct 24 '17 at 9:41











  • bit.ly/2w7H6y2 using link got all the multiselect attribute.

    – Rakesh Jesadiya
    Aug 23 '18 at 17:41














1












1








1


1






I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?










share|improve this question
















I have created a system.xml file with a multiselect type field somewhere in my admin system config. I just want to know on how to retrieve the selected values in that field?







magento2 module custom system.xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 24 '17 at 10:20









Sarfaraj

378318




378318










asked Oct 24 '17 at 9:19









Eubie AluadEubie Aluad

6311




6311













  • I found the solution by using Mage::getStoreConfig(section_group_field path)

    – Eubie Aluad
    Oct 24 '17 at 9:41











  • bit.ly/2w7H6y2 using link got all the multiselect attribute.

    – Rakesh Jesadiya
    Aug 23 '18 at 17:41



















  • I found the solution by using Mage::getStoreConfig(section_group_field path)

    – Eubie Aluad
    Oct 24 '17 at 9:41











  • bit.ly/2w7H6y2 using link got all the multiselect attribute.

    – Rakesh Jesadiya
    Aug 23 '18 at 17:41

















I found the solution by using Mage::getStoreConfig(section_group_field path)

– Eubie Aluad
Oct 24 '17 at 9:41





I found the solution by using Mage::getStoreConfig(section_group_field path)

– Eubie Aluad
Oct 24 '17 at 9:41













bit.ly/2w7H6y2 using link got all the multiselect attribute.

– Rakesh Jesadiya
Aug 23 '18 at 17:41





bit.ly/2w7H6y2 using link got all the multiselect attribute.

– Rakesh Jesadiya
Aug 23 '18 at 17:41










2 Answers
2






active

oldest

votes


















2














Define source model in system.xml



<field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<Module>Module Position</Module>
<source_model>VendorModuleModelConfigSourceConfigOption</source_model>
</field>


Now create ConfigOption.php at



<?php

namespace VendorModuleModelConfigSource;

class ConfigOption implements MagentoFrameworkOptionArrayInterface
{
public function toOptionArray()
{
return [
['value' => '1', 'label' => __('Top Right')],
['value' => '2', 'label' => __('Top Left')],
['value' => '3', 'label' => __('Middle Right')],
['value' => '4', 'label' => __('Middle')],
['value' => '5', 'label' => __('Middle Left')],
['value' => '6', 'label' => __('Bottom Right')],
['value' => '7', 'label' => __('Bottom Left')]
];
}
}


You will get multiselect value in string with value1,value2,value3 format.



You can use explode() function to convert it into array like this



$value = explode(',', $multiSelectValue);


For more info about how you can get system.xml config value refer this question



Magento2 -How to get data from system configuration






share|improve this answer


























  • I will note this sire!

    – Eubie Aluad
    Oct 24 '17 at 9:43



















0














Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like



$miltiselectValues = explode(',', $configValue);





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f198348%2fmagento2-retrieve-multiselect-values-in-system-xml%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Define source model in system.xml



    <field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <Module>Module Position</Module>
    <source_model>VendorModuleModelConfigSourceConfigOption</source_model>
    </field>


    Now create ConfigOption.php at



    <?php

    namespace VendorModuleModelConfigSource;

    class ConfigOption implements MagentoFrameworkOptionArrayInterface
    {
    public function toOptionArray()
    {
    return [
    ['value' => '1', 'label' => __('Top Right')],
    ['value' => '2', 'label' => __('Top Left')],
    ['value' => '3', 'label' => __('Middle Right')],
    ['value' => '4', 'label' => __('Middle')],
    ['value' => '5', 'label' => __('Middle Left')],
    ['value' => '6', 'label' => __('Bottom Right')],
    ['value' => '7', 'label' => __('Bottom Left')]
    ];
    }
    }


    You will get multiselect value in string with value1,value2,value3 format.



    You can use explode() function to convert it into array like this



    $value = explode(',', $multiSelectValue);


    For more info about how you can get system.xml config value refer this question



    Magento2 -How to get data from system configuration






    share|improve this answer


























    • I will note this sire!

      – Eubie Aluad
      Oct 24 '17 at 9:43
















    2














    Define source model in system.xml



    <field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <Module>Module Position</Module>
    <source_model>VendorModuleModelConfigSourceConfigOption</source_model>
    </field>


    Now create ConfigOption.php at



    <?php

    namespace VendorModuleModelConfigSource;

    class ConfigOption implements MagentoFrameworkOptionArrayInterface
    {
    public function toOptionArray()
    {
    return [
    ['value' => '1', 'label' => __('Top Right')],
    ['value' => '2', 'label' => __('Top Left')],
    ['value' => '3', 'label' => __('Middle Right')],
    ['value' => '4', 'label' => __('Middle')],
    ['value' => '5', 'label' => __('Middle Left')],
    ['value' => '6', 'label' => __('Bottom Right')],
    ['value' => '7', 'label' => __('Bottom Left')]
    ];
    }
    }


    You will get multiselect value in string with value1,value2,value3 format.



    You can use explode() function to convert it into array like this



    $value = explode(',', $multiSelectValue);


    For more info about how you can get system.xml config value refer this question



    Magento2 -How to get data from system configuration






    share|improve this answer


























    • I will note this sire!

      – Eubie Aluad
      Oct 24 '17 at 9:43














    2












    2








    2







    Define source model in system.xml



    <field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <Module>Module Position</Module>
    <source_model>VendorModuleModelConfigSourceConfigOption</source_model>
    </field>


    Now create ConfigOption.php at



    <?php

    namespace VendorModuleModelConfigSource;

    class ConfigOption implements MagentoFrameworkOptionArrayInterface
    {
    public function toOptionArray()
    {
    return [
    ['value' => '1', 'label' => __('Top Right')],
    ['value' => '2', 'label' => __('Top Left')],
    ['value' => '3', 'label' => __('Middle Right')],
    ['value' => '4', 'label' => __('Middle')],
    ['value' => '5', 'label' => __('Middle Left')],
    ['value' => '6', 'label' => __('Bottom Right')],
    ['value' => '7', 'label' => __('Bottom Left')]
    ];
    }
    }


    You will get multiselect value in string with value1,value2,value3 format.



    You can use explode() function to convert it into array like this



    $value = explode(',', $multiSelectValue);


    For more info about how you can get system.xml config value refer this question



    Magento2 -How to get data from system configuration






    share|improve this answer















    Define source model in system.xml



    <field id="Moduleposition" translate="Module" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <Module>Module Position</Module>
    <source_model>VendorModuleModelConfigSourceConfigOption</source_model>
    </field>


    Now create ConfigOption.php at



    <?php

    namespace VendorModuleModelConfigSource;

    class ConfigOption implements MagentoFrameworkOptionArrayInterface
    {
    public function toOptionArray()
    {
    return [
    ['value' => '1', 'label' => __('Top Right')],
    ['value' => '2', 'label' => __('Top Left')],
    ['value' => '3', 'label' => __('Middle Right')],
    ['value' => '4', 'label' => __('Middle')],
    ['value' => '5', 'label' => __('Middle Left')],
    ['value' => '6', 'label' => __('Bottom Right')],
    ['value' => '7', 'label' => __('Bottom Left')]
    ];
    }
    }


    You will get multiselect value in string with value1,value2,value3 format.



    You can use explode() function to convert it into array like this



    $value = explode(',', $multiSelectValue);


    For more info about how you can get system.xml config value refer this question



    Magento2 -How to get data from system configuration







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 3 mins ago









    Marko Durasic

    31




    31










    answered Oct 24 '17 at 9:28









    Prince PatelPrince Patel

    13.3k54676




    13.3k54676













    • I will note this sire!

      – Eubie Aluad
      Oct 24 '17 at 9:43



















    • I will note this sire!

      – Eubie Aluad
      Oct 24 '17 at 9:43

















    I will note this sire!

    – Eubie Aluad
    Oct 24 '17 at 9:43





    I will note this sire!

    – Eubie Aluad
    Oct 24 '17 at 9:43













    0














    Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like



    $miltiselectValues = explode(',', $configValue);





    share|improve this answer




























      0














      Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like



      $miltiselectValues = explode(',', $configValue);





      share|improve this answer


























        0












        0








        0







        Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like



        $miltiselectValues = explode(',', $configValue);





        share|improve this answer













        Just like all the other values from your system.xml. The result will be a string with comma separated values. So you have explode the string and have an array for better handling like



        $miltiselectValues = explode(',', $configValue);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 24 '17 at 9:29









        NikolasNikolas

        1,442412




        1,442412






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f198348%2fmagento2-retrieve-multiselect-values-in-system-xml%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto