0

I am trying to create a field in system config to display a list of column names of the cms_page table. How to achieve this. please help meenter image description here

1
0

Try This

app/code/VendoreName/BasicModule/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="vendorename" translate="label" sortOrder="201">
            <label>VendoreName</label>
        </tab>
        <section id="basicmodule" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Basic Module</label>
            <tab>vendorename</tab>
            <resource>VendoreName_BasicModule::basicmodule_config</resource>
            <group id="genaral_setting"
                   translate="label"
                   type="text"
                   sortOrder="10"
                   showInDefault="1"
                   showInWebsite="1"
                   showInStore="1">
                <label>General Settings</label>
                <field id="admin_list"
                       translate="label"
                       type="select"
                       sortOrder="10"
                       showInDefault="1"
                       showInWebsite="1"
                       showInStore="1">
                    <label>CMS Page Fields</label>
                    <source_model>VendoreName\BasicModule\Model\Adminhtml\System\Config\Source\CMSPageData</source_model>
                    <comment><![CDATA[Comment are <b>write here</b>.]]></comment>
                </field>
            </group>
        </section>
    </system>
</config>

app/code/VendoreName/BasicModule/Model/Adminhtml/System/Config/Source/CMSPageData.php

<?php

namespace VendoreName\BasicModule\Model\Adminhtml\System\Config\Source;

class CMSPageData implements \Magento\Framework\Option\ArrayInterface
{

    public function getOptionArray()
    {
        $options = [];

        $options['page_id'] = __('Entity ID');
        $options['title'] = __('Page Title');
        $options['page_layout'] = __('Page Layout');
        $options['meta_keywords'] = __('Page Meta Keywords');
        $options['meta_description'] = __(' Page Meta Description');
        $options['meta_title'] = __('Page Meta Title');
        $options['identifier'] = __('Page String Identifier');
        $options['content_heading'] = __('Page Content Heading');
        $options['content'] = __('Page Content');
        $options['creation_time'] = __('Page Creation Time');
        $options['update_time'] = __('Page Modification Time');
        $options['is_active'] = __('Is Page Active');
        $options['sort_order'] = __('Page Sort Order');
        $options['layout_update_xml'] = __('Page Layout Update Content');
        $options['custom_theme'] = __('Page Custom Theme');
        $options['custom_root_template'] = __('Page Custom Template');
        $options['custom_layout_update_xml'] = __('Page Custom Layout Update Content');
        $options['layout_update_selected'] = __('Page Custom Layout File');
        $options['custom_theme_from'] = __('Page Custom Theme Active From Date');
        $options['custom_theme_to'] = __('Page Custom Theme Active To Date');

        return $options;
    }

    public function getAllOptions()
    {
        $res = $this->getOptions();
        array_unshift($res, ['value' => '', 'label' => '']);
        return $res;
    }

    public function getOptions()
    {
        $res = [];
        foreach ($this->getOptionArray() as $index => $value) {
            $res[] = ['value' => $index, 'label' => $value];
        }
        return $res;
    }

    public function toOptionArray()
    {
        return $this->getOptions();
    }
}

I Hope This Helps You.

1
  • It works fine. Thank a lot! – THOR Hoang May 31 at 6:42

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.