Skip to content

Commit

Permalink
[Admin] Add custom query builder to payment method grid in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
pjedrzejewski committed Apr 29, 2016
1 parent 510753e commit a5d68c3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
Expand Up @@ -5,6 +5,8 @@ sylius_grid:
name: doctrine/orm
options:
class: %sylius.model.payment_method.class%
repository:
method: createListQueryBuilder
fields:
code:
type: string
Expand All @@ -23,9 +25,11 @@ sylius_grid:
options:
template: SyliusAdminBundle:Grid/Field:enabled.html.twig
filters:
code:
search:
type: string
label: sylius.ui.code
label: sylius.ui.search
options:
fields: [code, translation.name]
enabled:
type: boolean
label: sylius.ui.enabled
Expand Down
Expand Up @@ -15,6 +15,18 @@

class PaymentMethodRepository extends BasePaymentMethodRepository
{
/**
* {@inheritdoc}
*/
public function createListQueryBuilder()
{
return $this
->createQueryBuilder('o')
->addSelect('translation')
->leftJoin('o.translations', 'translation')
;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Sylius/Bundle/GridBundle/Doctrine/ORM/Driver.php
Expand Up @@ -46,10 +46,11 @@ public function getDataSource(array $configuration, Parameters $parameters)

$repository = $this->entityManager->getRepository($configuration['class']);

if (isset($configuration['repository']['method']) && isset($configuration['repository']['arguments'])) {
if (isset($configuration['repository']['method'])) {
$callable = [$repository, $configuration['repository']['method']];
$arguments = isset($configuration['repository']['arguments']) ? $configuration['repository']['arguments'] : [];

$queryBuilder = call_user_func_array($callable, $configuration['repository']['arguments']);
$queryBuilder = call_user_func_array($callable, $arguments);
} else {
$queryBuilder = $repository->createQueryBuilder('o');
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
interface ParametersParserInterface
{
/**
* @param array $parameters
* @param array $parameters
* @param Request $request
*
* @return array
Expand Down
Expand Up @@ -27,7 +27,7 @@ function let(ExpressionLanguage $expression)
$this->beConstructedWith($expression);
}

function it_implements_an_interface()
function it_implements_parameters_parser_interface()
{
$this->shouldImplement(ParametersParserInterface::class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Component/Grid/Definition/Grid.php
Expand Up @@ -101,7 +101,7 @@ public function getDriverConfiguration()
/**
* @param array $driverConfiguration
*/
public function setDriverConfiguration($driverConfiguration)
public function setDriverConfiguration(array $driverConfiguration)
{
$this->driverConfiguration = $driverConfiguration;
}
Expand Down

0 comments on commit a5d68c3

Please sign in to comment.