EDIT: I got it fixed. Whoever is interested in the solution:
1) <tab>Neusta</tab> had to become <tab>neusta</tab>
2) <source_model>Neusta\StockTrafficLight\Model\Source\Align</source_model> simply didn't exist.
Hey :-)
I'm currently trying to learn Magento2 and started developing an extension, but sadly my system.xml throws some unexpected errors which I'm not sure how to handle.
Notice: Undefined index: id in /magento2/vendor/magento/module-config/Model/Config/Structure/Element/Iterator.php on line 59 #0 /magento2/vendor/magento/module-config/Model/Config/Structure/Element/Iterator.php(59): Magento\Framework\App\ErrorHandler->handler(8, 'Undefined index...', '/magento2/vendo...', 59, Array) #1 /magento2/vendor/magento/module-config/Model/Config/Structure.php(85): Magento\Config\Model\Config\Structure\Element\Iterator->setElements(Array, 'default') #2 /magento2/var/generation/Magento/Config/Model/Config/Structure/Interceptor.php(24): Magento\Config\Model\Config\Structure->getTabs() #3 /magento2/vendor/magento/module-config/Model/Config/Structure.php(108): Magento\Config\Model\Config\Structure\Interceptor->getTabs() #4 /magento2/var/generation/Magento/Config/Model/Config/Structure/Interceptor.php(50): Magento\Config\Model\Config\Structure->getFirstSection() #5 /magento2/vendor/magento/module-config/Controller/Adminhtml/System/AbstractConfig.php(50): Magento\Config\Model\Config\Structure\Interceptor->getFirstSection() #6 [internal function]: Magento\Config\Controller\Adminhtml\System\AbstractConfig->dispatch(Object(Magento\Framework\App\Request\Http)) #7 /magento2/vendor/magento/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array) #8 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor->___callParent('dispatch', Array) #9 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Config\\...', 'dispatch', Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Array, 'adminAuthentica...') #10 /magento2/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http)) #11 [internal function]: Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #12 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array) #13 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Config\\...', 'dispatch', Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Array, 'designLoader') #14 /magento2/vendor/magento/framework/App/Action/Plugin/Design.php(39): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http)) #15 [internal function]: Magento\Framework\App\Action\Plugin\Design->aroundDispatch(Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #16 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array) #17 /magento2/vendor/magento/framework/Interception/Interceptor.php(136): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Config\\...', 'dispatch', Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Array, 'adminMassaction...') #18 /magento2/vendor/magento/module-backend/App/Action/Plugin/MassactionKey.php(33): Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #19 [internal function]: Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #20 /magento2/vendor/magento/framework/Interception/Interceptor.php(140): call_user_func_array(Array, Array) #21 /magento2/var/generation/Magento/Config/Controller/Adminhtml/System/Config/Index/Interceptor.php(40): Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor->___callPlugins('dispatch', Array, Array) #22 /magento2/vendor/magento/framework/App/FrontController.php(55): Magento\Config\Controller\Adminhtml\System\Config\Index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #23 [internal function]: Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http)) #24 /magento2/vendor/magento/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array) #25 /magento2/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array) #26 /magento2/vendor/magento/framework/Interception/Interceptor.php(136): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install') #27 /magento2/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #28 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #29 /magento2/vendor/magento/framework/Interception/Interceptor.php(140): call_user_func_array(Array, Array) #30 /magento2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array) #31 /magento2/vendor/magento/framework/App/Http.php(115): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #32 /magento2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch() #33 /magento2/index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #34 {main}
My system.xml looks like this:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd"> <system> <tab id="neusta" translate="label" sortOrder="10"> <label>Neusta</label> </tab> <section id="neusta_stocktraffclight" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Neusta_StockTrafficLight</label> <tab>Neusta</tab> <resource>Neusta_StockTrafficLight::neusta_stocktraffclight</resource> <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0"> <label>General</label> <field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enable Stock Traffic Light</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <comment> Enable 'Stock Traffic Lights'. </comment> </field> <field id="block_label" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Block Label</label> </field> <field id="text_align" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Text Align</label> <source_model>Neusta\StockTrafficLight\Model\Source\Align</source_model> </field> </group> </section> </system> </config>
Can anybody give me a hint what's wrong?
Cheerz!
Did you manage to fix it? I am having same issue.
Please help.
class Align implements \Magento\Framework\Option\ArrayInterface { public function toOptionArray() { return [ ['value' => -1, 'label' => __('None')], ['value' => 0, 'label' => __('0%')], ]; } }
Did you over ride the Arrayinterface and toOptinArray in your source model file Align.
Remove Tab id.
like <tab>netus</tab>
Your tab id is:
<tab id="neusta"
And you put:
<tab>Neusta</tab>
Correct way is to be exactly the same like id name so:
<tab>neusta</tab>
Not a capital letter.
Hi @ShivaHaze
Replace below code in your system.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd"> <system> <tab id="neusta" translate="label" sortOrder="10"> <label>Neusta</label> </tab> <section id="neusta_stocktraffclight" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Neusta StockTrafficLight</label> <tab>neusta</tab> <resource>Neusta_StockTrafficLight::neusta_stocktraffclight</resource> <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0"> <label>General</label> <field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enable Stock Traffic Light</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <comment> Enable 'Stock Traffic Lights'. </comment> </field> <field id="block_label" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Block Label</label> </field> <field id="text_align" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Text Align</label> <source_model>Neusta\StockTrafficLight\Model\Source\Align</source_model> </field> </group> </section> </system> </config>
I think you had already created Neusta\StockTrafficLight\Model\Source\Align file right?
The error in your code was that, you need to use tab id inside section tab. By mistake I think you had used tab id by capital letter.
Let me know if it worked.