<?php

namespace Oro\Bundle\SearchBundle\EventListener;

use Oro\Bundle\DataGridBundle\Event\BuildAfter;
use Oro\Bundle\SearchBundle\Datasource\SearchDatasource;

class SearchGridListener
{
    const FROM_PATH = '[source][query][from]';

    public function onBuildAfter(BuildAfter $event)
    {
        $grid = $event->getDatagrid();
        $datasource = $grid->getDatasource();

        if ($datasource instanceof SearchDatasource) {
            $from = $grid->getConfig()->offsetGetByPath(self::FROM_PATH);
            if (!empty($from)) {
                $datasource->getQuery()->from($from);
            }
        }
    }
}

<?php

namespace Oro\Bundle\SearchBundle\EventListener;

use Oro\Bundle\DataGridBundle\Event\BuildAfter;
use Oro\Bundle\SearchBundle\Datasource\SearchDatasource;

class SearchGridListener
{
    const FROM_PATH = '[source][query][from]';

    /**
     * Reads 'from' part in configuration and adds it to the query
     *
     * @param BuildAfter $event
     */
    public function onBuildAfter(BuildAfter $event)
    {
        $grid = $event->getDatagrid();
        $datasource = $grid->getDatasource();

        if ($datasource instanceof SearchDatasource) {
            $from = $grid->getConfig()->offsetGetByPath(self::FROM_PATH);
            if (!empty($from)) {
                $datasource->getQuery()->from($from);
            }
        }
    }
}

Make sure that user can build grids based on the backend search engine - fixed minor issues after review
BB-4318: Make sure that user can build grids based on the backend search engine
- fixed minor issues after review
