Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$field in doctrine_orm_callback is empty #472

Closed
webdevilopers opened this issue Jun 24, 2015 · 1 comment
Closed

$field in doctrine_orm_callback is empty #472

webdevilopers opened this issue Jun 24, 2015 · 1 comment

Comments

@webdevilopers
Copy link
Contributor

use Sonata\CoreBundle\Form\Type\BooleanType;

class PersonAdmin extends Admin
{
    protected function configureDatagridFilters(DatagridMapper $filterMapper)
    {
        $filterMapper
            ->add('employmentContracts', 'doctrine_orm_callback', array(
                    'callback' => function($queryBuilder, $alias, $field, $value) {
                            if (!isset($value['value'])) {
                                return;
                            }

                            if ($value['value'] == BooleanType::TYPE_YES) {
//                                $queryBuilder->andWhere(sprintf('SIZE(%s.%s) > 0', $alias, $field));
                                $queryBuilder->andWhere(sprintf('SIZE(%s.%s) > 0', $alias, 'employmentContracts'));
                            }

                            if ($value['value'] == BooleanType::TYPE_NO) {
                                $queryBuilder->andWhere(sprintf('SIZE(%s.%s) = 0', $alias, 'employmentContracts'));
                            }

                            return true;
                        }
                    ), 'choice', array(
                        'translation_domain' => 'SonataCoreBundle',
                        'choices' => array(
                            BooleanType::TYPE_YES => 'label_type_yes',
                            BooleanType::TYPE_NO  => 'label_type_no'
                        )
                    )
                )

When the filter is applied $field will be empty. It has to be set manually.

Source:
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/master/Filter/CallbackFilter.php#L29-36

But when I comment out the callback method the error message correctly displays the content:
Please provide a valid callback option "filter" for field "employmentContracts"
Since it uses $this->getName().

I guess $this->getName() should be passed to the call_user_func too, right?

@core23
Copy link
Member

core23 commented Aug 27, 2016

This issue should be fixed in the latest master version. Please have a look at the docs.

If this is still present, feel free to reopen this issue

@core23 core23 closed this as completed Aug 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants