34
loading...
This website collects cookies to deliver better user experience
/** @var array */
public const MODULE_HOOKS = [
'actionOrderGridDefinitionModifier',
'actionOrderGridQueryBuilderModifier',
];
/src/Core/Grid/GridFactory.php
./**
* {@inheritdoc}
*/
public function getGrid(SearchCriteriaInterface $searchCriteria)
{
$definition = $this->definitionFactory->getDefinition();
$data = $this->dataFactory->getData($searchCriteria);
// Here it is, hook that will modify the Grid data
$this->hookDispatcher->dispatchWithParameters('action' . Container::camelize($definition->getId()) . 'GridDataModifier', [
'data' => &$data,
]);
$filterForm = $this->filterFormFactory->create($definition);
$filterForm->setData($searchCriteria->getFilters());
return new Grid(
$definition,
$data,
$searchCriteria,
$filterForm
);
}
action<Identifier of a given component>GridDataModifier
.const GRID_ID = 'customer';
const
is defined here: /src/Core/Grid/Definition/Factory/CustomerGridDefinitionFactory.php
$params
array, the appropriate "tools" to be able to modify the selected component.hookActionOrderGridDefinitionModifier
, we have access to the Grid component definition, which is hidden behind the GridDefinitionInterface
implementation.$definition
variable in the code, we can manipulate the columns in the listing. In the case of the sample module, we add the carrier_name
column, which we display after the payment column. How do we know that the payment name column is payment? We can use, for example, the developer tools in the Chrome browser:$filters = $definition->getFilters();
$filters->add((new Filter(static::CARRIER_FIELD_NAME, TextType::class))
->setTypeOptions([
'required' => false,
])
->setAssociatedColumn(static::CARRIER_FIELD_NAME)
);
$params
argument to modify the information retrieval for a given list and we do what we need with it.$params['search_query_builder']
is a Doctrine instance of QueryBuilder
.addSelect
method we can... yes, add the fields we want to retrieve. This works very similar to the DbQuery class that you may now from PrestaShop core.$queryBuilder->addSelect(
'IF(carrier.name = "0", "'.Configuration::get('PS_SHOP_NAME').'", carrier.name) carrier_name'
);
actionSomethingListingFieldsModifier
. And, of course, it is.