3

I have created custom module configuration in admin panel to Enable in frontend and Modify Heading title. But the settings are not visible in the admin Store > Settings > Configuration.

I am following the below tutorial steps:

http://www.mage-world.com/blog/how-to-create-the-configuration-via-backend-for-a-custom-module.html

I have run the command setup:upgrade and cache:flush already and also it's not showing any error. I am using Magento ver. 2.1.3.

Please see the attached screenshot.

screenshot

My system.xml file code is:

<?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="tutorial" translate="label" sortOrder="1">
            <label>Tutorial</label>
        </tab>
        <section id="tutorial_simplenews" translate="label" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
            <label>Simple News</label>
            <tab>tutorial</tab>
            <resource>Tutorial_SimpleNews::config</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
                <label>General Settings</label>
                <field id="enable_in_frontend" translate="label" type="select" sortOrder="1" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable in frontend</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="head_title" translate="label comment" type="text" sortOrder="2" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Head title</label>
                    <comment>Fill head title of news list page at here</comment>
                    <validate>required-entry</validate>
                </field>
                <field id="lastest_news_block_position" translate="label" type="select" 
sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Lastest news block position</label>
                    <source_model>
                        Tutorial\SimpleNews\Model\System\Config\LastestNews\Position
                    </source_model>
                </field>
            </group>
        </section>
    </system>
</config>

Below is \Tutorial\SimpleNews\Model\System\Config\LastestNews\Position.php file code:

<?php

namespace Tutorial\SimpleNews\Model\System\Config\LastestNews;

use Magento\Framework\Option\ArrayInterface;

class Position implements ArrayInterface
{
    const LEFT      = 1;
    const RIGHT     = 2;
    const DISABLED  = 0;

    /**
     * Get positions of lastest news block
     *
     * @return array
     */
    public function toOptionArray()
    {
        return [
            self::LEFT => __('Left'),
            self::RIGHT => __('Right'),
            self::DISABLED => __('Disabled')
        ];
    }
}
8
  • please show your sytem.xml file to check more. Feb 27, 2017 at 6:39
  • I have edited the question. Please check. Feb 27, 2017 at 6:50
  • Have you check your acl file ? Tutorial_SimpleNews::config
    – Priyank
    Feb 27, 2017 at 6:51
  • Yes I have checked acl file. Feb 27, 2017 at 6:54
  • Please check by removing the last field you have. If it works then the issue must be with Tutorial\SimpleNews\Model\System\Config\LastestNews\Position.php files Feb 27, 2017 at 7:10

2 Answers 2

6

Its because you haven't written the source_model node correctly, There should be no spaces while specifying its value.

<?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="tutorial" translate="label" sortOrder="1">
            <label>Tutorial</label>
        </tab>
        <section id="tutorial_simplenews" translate="label" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
            <label>Simple News</label>
            <tab>tutorial</tab>
            <resource>Tutorial_SimpleNews::config</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
                <label>General Settings</label>
                <field id="enable_in_frontend" translate="label" type="select" sortOrder="1" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable in frontend</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="head_title" translate="label comment" type="text" sortOrder="2" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Head title</label>
                    <comment>Fill head title of news list page at here</comment>
                    <validate>required-entry</validate>
                </field>
                <field id="lastest_news_block_position" translate="label" type="select" 
sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Lastest news block position</label>
                    <source_model>Tutorial\SimpleNews\Model\System\Config\LastestNews\Position</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

Use this modified code and check.

2
  • Great!! Thank you so much, now it's working fine. Feb 27, 2017 at 9:00
  • you are welcome. :) Happy to help Feb 27, 2017 at 9:01
3
  <?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="tutorial" translate="label" sortOrder="1">
            <label>Tutorial</label>
        </tab>
        <section id="tutorial_simplenews" translate="label" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
            <label>Simple News</label>
            <tab>tutorial</tab>
            <resource>Tutorial_SimpleNews::config</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" 
showInWebsite="1" showInStore="1">
                <label>General Settings</label>
                <field id="enable_in_frontend" translate="label" type="select" sortOrder="1" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable in frontend</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="head_title" translate="label comment" type="text" sortOrder="2" 
showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Head title</label>
                    <comment>Fill head title of news list page at here</comment>
                    <validate>required-entry</validate>
                </field>
                <field id="lastest_news_block_position" translate="label" type="select" 
sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Lastest news block position</label>
                    <source_model>Tutorial\SimpleNews\Model\System\Config\LastestNews\Position</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

Try

<?php
namespace Tutorial\SimpleNews\Model\System\Config\LastestNews;

class Position implements \Magento\Framework\Option\ArrayInterface
{
    public function toOptionArray()
    {
        return [
            ['value' => '0', 'label' => __('Disabled')],
            ['value' => '1', 'label' => __('LEFT')],
            ['value' => '2', 'label' => __('Right')],           

        ];
    }
}
2
  • Hi mageDev0688 try it Feb 27, 2017 at 7:30
  • Hi Nikhil, Yes I have tried the above code in the Position.php. But nothing happen issue is as it is displaying the empty screen. If I remove the Position filed from system.xml it's working but within the position field it's not working. Feb 27, 2017 at 8:37

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.