2

System Configuration

<field id="test" translate="label" type="multiselect" sortOrder="11" showInDefault="1" showInStore="1" showInWebsite="1">
 <label>Cms Page</label>
<source_model>Namespace\Module\Model\Test</source_model>
</field>

Test.php

public function toOptionArray()
    {
        $options = [
            [
                'label' => __('-- Please select --'),
                'value' => '',
            ],
            [
                'label' => __('Home Page '),
                'value' => 'cms_index_index',
            ],
            [
                'label' => __('404 Page'),
                'value' => 'cms_page_view',
            ],
            [
                'label' => __('Product'),
                'value' => 'catalog_product_view',
            ],
            [
                'label' => __('Category'),
                'value' => 'catalog_category_view',
            ],

        ];
        return $options;

How to get all pages dynamically ?

7

You need to use the Magento\Cms\Model\Config\Source\Page source model.

So replace:

<source_model>Namespace\Module\Model\Test</source_model>

With:

<source_model>Magento\Cms\Model\Config\Source\Page</source_model>
| improve this answer | |
2

You can use CMS config model into your system.xml to get pages dynamically.

<field id="test" translate="label" type="multiselect" sortOrder="11" showInDefault="1" showInStore="1" showInWebsite="1">
   <label>Cms Page</label>
   <source_model>Magento\Cms\Model\Config\Source\Page</source_model>
</field>

For reference you can find the below file.

\vendor\magento\module-cms\etc\adminhtml\system.xml
| improve this answer | |
  • 1
    I want to add some custom page select option also category,product,cart etc... – Magento 2 Oct 25 '16 at 16:22

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.