Package Attribute not installing ORM

Permalink 2 users found helpful
Hello,

I've been following this (https://documentation.concrete5.org/developers/attributes/creating-custom-attribute-types/including-an-attribute-type-in-a-package) to create a custom attribute type.

However, including an attribute type in a package doesn't work as described in the documentation. The package doesn't install the Settings or Value ORM whatsoever.

I get the following error when trying to create a new attribute of my type through the Dashboard->Pages&Themes->Attributes:

[ Doctrine \ ORM \ Mapping \ MappingException
Class "Concrete\Package\ThinkStory\Src\Concrete\Entity\Attribute\Key\Settings\TimbreSettings" sub class of "Concrete\Core\Entity\Attribute\Key\Settings\Settings" is not a valid entity or mapped super class.]

When I look into the database, neither the settings or value tables exist.

When I try to install my attribute type through the attribute interface, when the code in in public/application/attribute and public/src, the attribute works fine and installs the attribute perfectly, and I have to problems at all using it. I only have problems when I try to include it in my package.

Any help is appreciated

 
mesuva replied on at Permalink Reply
mesuva
We've been hitting this error message occasionally with Community Store, which creates its own attribute categories. Sometimes it would trigger on installs or upgrades, or when refreshing the database entities via the dashboard, but not a way where we could pinpoint the cause. I've seen people raise this issue for years, but their issue either goes away, or the do some sort of re-install.

Recently I was able to trigger this error repeatedly, and from that spend some time working out what is happening to trigger this kind of Doctrine error.

What I found was that at certain times during start up, Doctrine wouldn't load up all the entities within packages, and with things not loaded, the Doctrine mapping becomes invalid.

I tracked the particular issue down to not something with Community Store, but _another package_, installed before Community Store that did some sort of attribute related functionality during the on_start function of the package. The code within the on_start was firing all the time, when it really was only applicable to when a front-end page is viewed.

I found that I could install Community Store first, then the troublesome package second, and not trigger the exception. But if I installed Community Store second, it would trigger the MappingException. I was then able to comment out a single line within the package's on_start, and the error went away.

The exact reason why this was happening I don't know, but my guess is that something about the code that did an attribute lookup (it was checking if an attribute existed), initialises all the doctrine related stuff, then caches it, and further packages that are supposed to load up further doctrine entities miss out on being loaded.

It might be that this is just one way to trigger the error and may not specifically be the case for you.

But my first question would be: do you have any other packages installed, and if so, do they have code within their on_start package function?
Hubble replied on at Permalink Reply
Thank you for your reply.

Unfortunately I had also tested the package on a fresh install of Concrete5 without any other packages, and I would get the same issue, but I'll check if my package's on_start could be causing problems.
mesuva replied on at Permalink Reply
mesuva
Interesting, it sounds like I only came across one particular way the error can surface.

I've just pushed up a new custom attribute type here:
https://github.com/Mesuva/msv_multiple_file_selector_attribute...

I'd be curious if that installs cleanly for you (it also has settings that extend for Concrete\Core\Entity\Attribute\Key\Settings\Settings)
Hubble replied on at Permalink Reply
Thank you for the example! Works fine.

In my package, I had my files in the same locations with the appropriate namespaces, but I'm getting
"Class 'Concrete\Package\ThinkStory\Entity\Attribute\Key\Settings\TimbreSettings' not found",

even though I have the settings controller at packages/think_story/src/Concrete/Entity/Attribute/Key/Settings

If I try to change the namespace to include the src/Concrete, I'm able to at least start adding and attribute with my attribute type, but when I try to save the attribute settings I get the following error:

Class "Concrete\Package\ThinkStory\Src\Concrete\Entity\Attribute\Key\Settings\TimbreSettings" sub class of "Concrete\Core\Entity\Attribute\Key\Settings\Settings" is not a valid entity or mapped super class.
mesuva replied on at Permalink Best Answer Reply
mesuva
In your package controller, what do you have as the minimum version required?
I think it may need to be 8.0 or above to load up the classes automatically in this case.
Hubble replied on at Permalink Reply
OMG that was it! In my package controller I had the minimum version at 5.7 something before!

Thank you so much for your help, you're a lifesaver!