0

I have created the block file which extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray from Module-Config. Now I need to get Protected property from the above core file. Please provide me a solution

\Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray

 public function addColumn($name, $params)
        {
            $this->_columns[$name] = [
                'label' => $this->_getParam($params, 'label', 'Column'),
                'size' => $this->_getParam($params, 'size', false),
                'style' => $this->_getParam($params, 'style'),
                'class' => $this->_getParam($params, 'class'),
                'renderer' => false,
            ];
            if (!empty($params['renderer']) && $params['renderer'] instanceof \Magento\Framework\View\Element\AbstractBlock) {
                $this->_columns[$name]['renderer'] = $params['renderer'];
            }
        }

I need to get "_columns" to my custom template System.xml

<field id="fieldslide" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Small image</label>
                    <frontend_model>X\Y\Block\Adminhtml\System\Config</frontend_model>
                    <backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>                    
                    <comment>Image size should be in Bytes(1 KB = 1024 Bytes, 10 KB = 10240 Bytes, 50 KB = 51200 Bytes, 100 KB = 102400 Bytes, 150 KB = 153600 Bytes)</comment>
                </field>
8
  • which property of this class do you want to access?
    – Manish Joy
    Jan 12, 2018 at 10:19
  • see updated post @Manish Joy
    – Jaisa
    Jan 12, 2018 at 10:28
  • You can use this property in the class which inherits it. what's the error that you are getting?
    – Manish Joy
    Jan 12, 2018 at 10:32
  • Are you want to create serialize field in configration
    – Aman Alam
    Jan 12, 2018 at 10:33
  • Yes you are correct @Aman Alam
    – Jaisa
    Jan 12, 2018 at 10:34

2 Answers 2

1

Protected methods / class are available from exteding class. Only private are blocked.

So, when your Block extends a parent class which has protected _columns property, then you should have a access to it

0
1

Here is the solution and how your serializer should look.

<field id="sampleid" translate="label" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Sample Label</label>
    <frontend_model>Namespace\Module\Block\Adminhtml\System\Config\Form\Field\AnyblockName</frontend_model>
    <backend_model>Magento\Config\Model\Config\Backend\Serialized</backend_model>
    <comment>Image size should be in Bytes(1 KB = 1024 Bytes, 10 KB = 10240 Bytes, 50 KB = 51200 Bytes, 100 KB = 102400 Bytes, 150 KB = 153600 Bytes)</comment>
</field>

You block file should look like this. Namespace\Module\Block\Adminhtml\System\Config\Form\Field\AnyblockName.php

<?php
namespace Namespace\Module\Block\Adminhtml\System\Config\Form\Field;

class AnyblockName extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
    protected function _prepareToRender()
    {
        $this->addColumn('col_1', [
            'label' => __('Column 1')
        ]);
        $this->addColumn('col_2', [
            'label' => __('Column 2')
        ]);
        $this->addColumn('position', [
            'label' => __('Position')
        ]);
        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
    }
}
1
  • Thank you Aman Alam, But I need to use _columns in my Template. And I have found the solution which is present in array.phtml in Moduel-config
    – Jaisa
    Jan 12, 2018 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.