Skip to content

Loading…

Fill in reference document about overriding each part of a bundle #735

Closed
weaverryan opened this Issue · 16 comments

9 participants

@weaverryan
Symfony member

See the new entry introduced in sha: 8c97795

I think much of it will just be a reference (links to to other places), while some topics (because it's hard or impossible to override), should be discussed

@weaverryan
Symfony member

I've made some progress on this issue (as you can see, each section is short, and just points elsewhere), but there are several other areas that we can still cover. Many of those are sitting in the document and are waiting for your contribution :)

@userfriendly

If I may I would like to ping you guys regarding the "Entities & Entity mapping" section in that document. Got lots and lots of questions about this - it doesn't seem to be covered in the documentation, and in the IRC channel I get confusing and contradicting suggestions about it.

@WouterJ
Symfony member

Related PR: #2333

@xabbuh
Symfony member

Doctrine added support to override attributes and so on in one of the latest version. Maybe we can use that?

@WouterJ
Symfony member

Doctrine 2.3.x is used since Symfony 2.1, so we can use it.

@stof
Symfony member

AttributeOverride can be used to overwrite the mapping of an inherited field. So it makes it easier when a bundle provides a mapped superclass.
But overriding an entity of a bundle is still impossible.

@xabbuh
Symfony member

That's right, but do you think that's a reason not to mention the already existing possibilities? Even if it's only one sentence like

It is not possible to override an entity of bundle. However, if a bundle provides a mapped superclass one can override attributes and associations.

and link it to the Doctrine documentation.

@WouterJ
Symfony member

@xabbuh I'm :+1: for that, not finished documentation is worse.

@stof
Symfony member

@xabbuh sure it can be mentionned, but not as a way to overwrite entities

@DHorchler

Hello everybody,
why not mention that Sympatch can be an alternative to override any part of a bundle, including entities, and is not even limited to PHP code?
https://github.com/DHorchler/SympatchBundle

@WouterJ
Symfony member

I didn't look at the Sympatch bundle yet, but if it can be the solution for overriden bundle parts, I'm :+1: for it. I think including relevant and great bundles in the documentation is a usefull evolution.

@stof
Symfony member

This bundle is a hack IMO. It modifies the content of the vendor bundles, which does not play well with vendor updates

@DHorchler

@stof hack sounds negative. I don't consider myself a hacker :-) .

Of course, my bundle's approach is much different from all other recommendations that deal with overriding foreign code.
Maybe it even lacks a certain elegance. But guess what? It works.

I gave a procedure for code base updates which consists in deactivate all patches, upgrade the code base and reactivate the patches, just 2 extra console commands (I believe that could be automated).

Can I guarantee that after vendor updates everything will work? I can't. But chances are good that it will.
Can anybody guarantee that when you override parts of foreign code and then that code is updated that still everything will work? I don't think so.

@trsteel88

If it is not possible to overwrite an entity. How is everyone using vendor bundles for projects?

Eg, a blog. Sometimes you may need to add additional fields to a post entity or you may want to add a blog category introduction field.

From what I understand, with the mapped super classes, it means you MUST create the sub classes in the app specific bundle. Also, this does not work for One-To-Many associations on the mapped super class so you couldn't setup a default structure for the blog with posts/categories?

Is it not possible to somehow intercept the mappings with an event and just point the mapped at a different class if it exists?

@merk

OneToMany Associations work fine with this method. Doctrine provides a ResolveTargetEntityListener that lets you define relationships against abstract classes or interfaces that can be overridden to point to a concrete implementation of an entity at runtime.

@drgomesp

Does anyone have a solution for the overriding of mapped entities yet?

@weaverryan weaverryan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.