PHP code example of magentix / magento2-module-form-select2

1. Go to this page and download the library: Download magentix/magento2-module-form-select2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

magentix / magento2-module-form-select2 example snippets




declare(strict_types=1);

namespace Vendor\Module\Ui\DataProvider\Product\Form\Modifier;

use Magento\Ui\DataProvider\Modifier\ModifierInterface;

class ProductTest implements ModifierInterface
{
    public function modifyData(array $data): array
    {
        return $data;
    }

    public function modifyMeta(array $meta): array
    {
        $attributeCode = 'product_test'; // Update with your attribute code
    
        $config = $meta['product-details']['children']['container_' . $attributeCode]['arguments']['data']['config'] ?? false;
        
        if (!$config) {
            return $meta;
        }

        $config['formElement'] = 'select';
        $config['elementTmpl'] = 'Magentix_FormSelect2/form/element/select2';
        $config['component'] = 'Magentix_FormSelect2/js/form/element/select2';
        $config['select2'] = [
            'minimumInputLength' => 3,
            'type' => 'formSelectSearchProduct', // formSelectSearchProduct, formSelectSearchCustomer or custom
        ];

        $meta['product-details']['children'][$attributeCode]['arguments']['data']['config'] = $config;

        return $meta;
    }
}