<commit_before><?php

namespace Dotdigitalgroup\Email\Block\Adminhtml\Config;

class Customdatafields extends
    \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{

    /**
     * Customer attributes.
     *
     */
    protected $_attributeRenderer;

    /**
     * Customer datafields.
     */
    protected $_datafieldRenderer;


    protected $datafieldsFactory;
    protected $_elementFactory;

    /**
     * Customdatafields constructor.
     *
     * @param \Magento\Framework\Data\Form\Element\Factory                             $elementFactory
     * @param \Dotdigitalgroup\Email\Model\Config\Source\Datamapping\DatafieldsFactory $datafields
     * @param \Magento\Backend\Block\Template\Context                                  $context
     * @param array                                                                    $data
     */
    public function __construct(
        \Magento\Framework\Data\Form\Element\Factory $elementFactory,
        \Dotdigitalgroup\Email\Model\Config\Source\Datamapping\DatafieldsFactory $datafields,
        \Magento\Backend\Block\Template\Context $context,
        $data = []
    ) {
        $this->_elementFactory   = $elementFactory;
        $this->datafieldsFactory = $datafields->create();
        $this->_addAfter         = false;

        $this->_addButtonLabel = __('Add New Attribute');
        parent::__construct($context, $data);

    }

    protected function _prepareToRender()
    {
        $this->_getDatafieldRenderer = null;
        $this->_getAttributeRenderer = null;
        $this->addColumn(
            'attribute',
            array(
                'label' => __('Attribute'),
                'style' => 'width:120px',
            )
        );
        $this->addColumn(
            'datafield', array(
                'label' => __('DataField'),
                'style' => 'width:120px',
            )
        );
    }

    public function renderCellTemplate($columnName)
    {
        if ($columnName == 'attribute' && isset($this->_columns[$columnName])) {

            $options = $this->getElement()->getValues();
            $element = $this->_elementFactory->create('select');
            $element->setForm(
                $this->getForm()
            )->setName(
                $this->_getCellInputElementName($columnName)
            )->setHtmlId(
                $this->_getCellInputElementId('<%- _id %>', $columnName)
            )->setValues(
                $options
            );

            return str_replace("\n", '', $element->getElementHtml());
        }

        if ($columnName == 'datafield' && isset($this->_columns[$columnName])) {

            $options = $this->datafieldsFactory->toOptionArray();
            $element = $this->_elementFactory->create('select');
            $element->setForm(
                $this->getForm()
            )->setName(
                $this->_getCellInputElementName($columnName)
            )->setHtmlId(
                $this->_getCellInputElementId('<%- _id %>', $columnName)
            )->setValues(
                $options
            );

            return str_replace("\n", '', $element->getElementHtml());
        }

        return parent::renderCellTemplate($columnName);
    }

    /**
     * @param \Magento\Framework\DataObject $row
     */
    protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
    {
        $options = [];

        $options['option_' . $this->_getAttributeRenderer()->calcOptionHash(
            $row->getData('attribute')
        )]
            = 'selected="selected"';
        $options['option_' . $this->_getDatafieldRenderer()->calcOptionHash(
            $row->getData('datafield')
        )]
            = 'selected="selected"';

        $row->setData('option_extra_attrs', $options);
    }

    protected function _getAttributeRenderer()
    {

        $this->_attributeRenderer = $this->getLayout()->createBlock(
            'Dotdigitalgroup\Email\Block\Adminhtml\Config\Select',
            '',
            ['data' => ['is_render_to_js_template' => true]]
        );

        return $this->_attributeRenderer;
    }

    protected function _getDatafieldRenderer()
    {
        $this->_datafieldRenderer = $this->getLayout()->createBlock(
            'Dotdigitalgroup\Email\Block\Adminhtml\Form\Datafield',
            '',
            ['data' => ['is_render_to_js_template' => true]]
        );

        return $this->_datafieldRenderer;
    }

    public function _toHtml()
    {
        return '<input type="hidden" id="' . $this->getElement()->getHtmlId()
        . '"/>' . parent::_toHtml();

    }

}<commit_msg>Update custom order attributes mapping form #2<commit_after><?php

namespace Dotdigitalgroup\Email\Block\Adminhtml\Config;

class Customdatafields extends
    \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{

    /**
     * Customer attributes.
     *
     */
    protected $_attributeRenderer;

    /**
     * Customer datafields.
     */
    protected $_datafieldRenderer;


    protected $datafieldsFactory;
    protected $_elementFactory;

    /**
     * Customdatafields constructor.
     *
     * @param \Magento\Framework\Data\Form\Element\Factory                             $elementFactory
     * @param \Dotdigitalgroup\Email\Model\Config\Source\Datamapping\DatafieldsFactory $datafields
     * @param \Magento\Backend\Block\Template\Context                                  $context
     * @param array                                                                    $data
     */
    public function __construct(
        \Magento\Framework\Data\Form\Element\Factory $elementFactory,
        \Dotdigitalgroup\Email\Model\Config\Source\Datamapping\DatafieldsFactory $datafields,
        \Magento\Backend\Block\Template\Context $context,
        $data = []
    ) {
        $this->_elementFactory   = $elementFactory;
        $this->datafieldsFactory = $datafields->create();
        $this->_addAfter         = false;

        $this->_addButtonLabel = __('Add New Attribute');
        parent::__construct($context, $data);

    }

    protected function _prepareToRender()
    {
        $this->_getDatafieldRenderer = null;
        $this->_getAttributeRenderer = null;
        $this->addColumn(
            'attribute',
            array(
                'label' => __('Attribute'),
                'style' => 'width:120px',
            )
        );
        $this->addColumn(
            'datafield', array(
                'label' => __('DataField'),
                'style' => 'width:120px',
            )
        );
    }

    public function renderCellTemplate($columnName)
    {
        if ($columnName == 'attribute' && isset($this->_columns[$columnName])) {

            $options = $this->getElement()->getValues();
            $element = $this->_elementFactory->create('select');
            $element->setForm(
                $this->getForm()
            )->setName(
                $this->_getCellInputElementName($columnName)
            )->setHtmlId(
                $this->_getCellInputElementId('<%- _id %>', $columnName)
            )->setValues(
                $options
            );

            return str_replace("\n", '', $element->getElementHtml());
        }

        if ($columnName == 'datafield' && isset($this->_columns[$columnName])) {

            $options = $this->datafieldsFactory->toOptionArray();
            $element = $this->_elementFactory->create('select');
            $element->setForm(
                $this->getForm()
            )->setName(
                $this->_getCellInputElementName($columnName)
            )->setHtmlId(
                $this->_getCellInputElementId('<%- _id %>', $columnName)
            )->setValues(
                $options
            );

            return str_replace("\n", '', $element->getElementHtml());
        }

        return parent::renderCellTemplate($columnName);
    }

    /**
     * @param \Magento\Framework\DataObject $row
     */
    protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
    {
        $options = [];

        $options['option_' . $this->_getAttributeRenderer()->calcOptionHash(
            $row->getData('attribute')
        )]
            = 'selected="selected"';
        $options['option_' . $this->_getDatafieldRenderer()->calcOptionHash(
            $row->getData('datafield')
        )]
            = 'selected="selected"';

        $row->setData('option_extra_attrs', $options);
    }

    protected function _getAttributeRenderer()
    {

        $this->_attributeRenderer = $this->getLayout()->createBlock(
            'Dotdigitalgroup\Email\Block\Adminhtml\Config\Select',
            '',
            ['data' => ['is_render_to_js_template' => true]]
        );

        return $this->_attributeRenderer;
    }

    protected function _getDatafieldRenderer()
    {
        $this->_datafieldRenderer = $this->getLayout()->createBlock(
            'Dotdigitalgroup\Email\Block\Adminhtml\Config\Select',
            '',
            ['data' => ['is_render_to_js_template' => true]]
        );

        return $this->_datafieldRenderer;
    }

    public function _toHtml()
    {
        return '<input type="hidden" id="' . $this->getElement()->getHtmlId()
        . '"/>' . parent::_toHtml();

    }

}
{'fraction_non_alphanumeric': 0.13986689566337485, 'fraction_numerical': 0.001395448690425075, 'mean_word_length': 1.919774365402695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4218358', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2409, 'n_words': 350}