Documentation

Filter customization

Filter customization is ensured by moving CRM instance in element lists for \Bitrix\Crm\Filter\Factory to [link=13976638]Service\Container[/link].

As in the [link=14018116]previous examples[/link], this class instance must be extended.

use Bitrix\Crm\Service;
use Bitrix\Main\DI;
use Bitrix\Crm\Filter;

$filterFactory = new class extends Filter\Factory {
    
};

DI\ServiceLocator::getInstance()->addInstance(
    'crm.filter.factory',
    $filterFactory
);

For example, you need to modify the filter for deal search.

It's sufficient to only re-define provider for deals and/or filter and implement your own custom logic.

use Bitrix\Crm\Service;
use Bitrix\Crm\Filter;
use Bitrix\Main;

class MyFilterFactory extends Filter\Factory
{
    public function getDataProvider(Main\Filter\EntitySettings $settings): Main\Filter\DataProvider
    {
        if ($settings instanceof Filter\DealSettings)
        {
            return new class($settings) extends Filter\DealDataProvider
            {
                // some custom info about fields
            };
        }
        
        return parent::getDataProvider($settings);
    }
    
    public function createFilter(
		$ID,
		Main\Filter\DataProvider $entityDataProvider,
		array $extraDataProviders = null,
		array $params = null
	): Filter\Filter
	{
		if ($entityDataProvider instanceof Filter\DealDataProvider)
		{
		    return new class ($ID, $entityDataProvider, (array)$extraDataProviders, (array)$params) extends Filter\Filter {
		        // some custom logic
		    };
		}
		
		return parent::createFilter($ID, $entityDataProvider, (array)$extraDataProviders, (array)$params);
	}
}


© «Bitrix24», 2001-2024
Up