I have a bundle of behaviors (like IDublinCore) and would like to add a collective.taxonomy-behavior (collective.taxonomy.generated.university) to it. Now the taxonomy-behavior is generated at runtime with a Wrapper (see collective/taxonomy/generated.py#L43).
This is my bundle behavior.
@provider(IFormFieldProvider)
class IFHNWBasic(
IBasic,
ICategorization,
IShortName,
IExcludeFromNavigation,
IVersionable,
model.Schema,
):
"""Behavior with basic fields for FHNW"""
Has anybody an idea how I can achieve that?
As a workaround, I add it to the content type directly.
What we did to achieve this (edited to your universities case and assuming you have an addon package with a GS profile):
create a folder profiles/default/taxonomies and add a file university.cfg
The content of university.cfg can look like this:
[taxonomy]
name = universities
title = Universities
description =
default_language = de
field_title = Universities
field_description =
taxonomy_fieldset = default # or whatever you want
create a universities.xml in the same folder with vdex data:
Thx for your answer. Your suggestion is broadly what I am doing right now as a workaround.
Maybe I was not specific in my initial question: In the end I would like to have the universitiy-taxonomy-behavior as a part of IFHNWBasic. So when I assign IFHNWBasic to a contenttype the taxonomy-behavior is added as well to the contenttype.
I thought of something like this (but it's not working).
@provider(IFormFieldProvider)
class IFHNWBasic(
IBasic,
ICategorization,
IShortName,
IExcludeFromNavigation,
IVersionable,
Wrapper("university")
model.Schema,
):
"""Behavior with basic fields for FHNW"""
It might be that this is not possible at all or very complex.
@adrianschulz You might be able to do something like this if you can arrange for it to happen late enough during startup that the ZCML configuration for collective.taxonomy is already active:
from collective.taxonomy.generated import universities
IFHNWBasic.__bases__ = IFHNWBasic.__bases__ + (universities,)
but this is kind of dark Python magic and I'm not sure I can anticipate possible side effects.
Generally I would discourage trying to bundle behaviors like this. It's not that hard to list them out separately in the type info XML, and it keeps things flexible if you need to change the order or replace one of them for a specific content type. I regret creating the IDublinCore bundle.