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

Allow method/property to return false #3790

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

stephanvierkant
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tickets fixes #3681
License MIT
Doc PR api-platform/docs#...

When using a method or property (like this example from the documentation) you can't return false right now.

Currently, this example:

<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
/**
 * @ApiResource(mercure="object.mercureOptions()")
 */
class Book
{
    /**
     * @ORM\Column(type="string")
     */
    private $foo;

    public function mercureOptions()
    {
        if ($this->foo !== 'bar') {
            return false;
        }

        return ['private' => false];
    }

will give an error message:

The value of the "mercure" attribute of the "Book" resource class must be a boolean, an array of options or an expression returning this array, "boolean" given.'

This 'must be boolean (..), "boolean" given' is very confusing.

With this PR, this example will work.

@dunglas dunglas merged commit 000a56a into api-platform:2.5 Oct 26, 2020
@dunglas
Copy link
Member

dunglas commented Oct 26, 2020

Thanks @stephanvierkant

@stephanvierkant stephanvierkant deleted the mercure-method-false branch October 26, 2020 09:26
@stephanvierkant stephanvierkant restored the mercure-method-false branch October 26, 2020 10:05
@stephanvierkant
Copy link
Contributor Author

@dunglas Any idea when a new (2.5) release would be tagged/published?

@stephanvierkant stephanvierkant deleted the mercure-method-false branch November 6, 2022 12:25
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

Successfully merging this pull request may close these issues.

2 participants