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

Call to a member function get() on null ($this->translations) #20

Open
Gregor2203 opened this issue Dec 15, 2021 · 1 comment
Open

Call to a member function get() on null ($this->translations) #20

Gregor2203 opened this issue Dec 15, 2021 · 1 comment

Comments

@Gregor2203
Copy link

Gregor2203 commented Dec 15, 2021

Hello
I extended class ArticleCategory and it works, but if I trying to add new article got error "Call to a member function get() on null".
This $this->translations, initialised in constructor (TranslatableTrait), return NULL. It's weird.

public function __construct()
    {
        $this->translations = new ArrayCollection();
    }

My model:

declare(strict_types=1);

namespace App\Entity\Blog;

use Doctrine\ORM\Mapping as ORM;
use Odiseo\BlogBundle\Model\ArticleCategory as BaseArticleCategory;
use Odiseo\BlogBundle\Model\ArticleCategoryTranslation;
use Odiseo\BlogBundle\Model\ArticleCategoryInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="odiseo_blog_article_category")
 */
class ArticleCategory extends BaseArticleCategory implements ArticleCategoryInterface
{
    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $wp_id;

    /**
     * @ORM\ManyToOne(targetEntity=ArticleCategory::class)
	 * @ORM\JoinColumn(onDelete="CASCADE")
     */
    private $parent;

    public function getWpId(): ?int
    {
        return $this->wp_id;
    }

    public function setWpId(int $wp_id): self
    {
        $this->wp_id = $wp_id;

        return $this;
    }

    public function getParent(): ?self
    {
        return $this->parent;
    }

    public function setParent(?self $parent): self
    {
        $this->parent = $parent;

        return $this;
    }
	
	protected function createTranslation(): ArticleCategoryTranslation
    {
        return new ArticleCategoryTranslation();
    }
}

odiseo_blog.yaml

imports:    
    - { resource: "@OdiseoSyliusBlogPlugin/Resources/config/config.yaml" }

odiseo_blog:
    resources:
        article_category:
            classes:
                model: App\Entity\Blog\ArticleCategory

2021-12-16_00-24-55

Thanks in advance for any help!

@JordiDekker
Copy link

Just had the same issue. Found that the BlogBundle has a categories element with an ArticleType type that uses an EntityType with the Odiseo\BlogBundle\Model\ArticleCategory class.

I think the easiest way is to create an FormExtension that replaces the categories field, where you can use your own ArticleCategory class in the class option.

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