Hi
I am working with the fullcalendar module, that uses the colors module to set colors on node type, taxonomy or users. But I would like to set colors based on an entity reference field.
Since it is possible for taxonomies, I guess it won't be that difficult to add entity references.
In my case I have content type A and B. When creating B, it always has a reference to a node of type A. The I am showing nodes of type B in a calendar (with fullcalendar) and I would like to give threm a color based on the entity reference field.
I'll look into this after my holiday. But if someone has done this before, or wants to point me in the right direction, this would be great!
Comments
Comment #1
tim.plunkettWhat part of the entity that's being referenced would be used? The title? A field on that other entity?
That's the reason this isn't done yet :)
Comment #2
aspilicious CreditAttribution: aspilicious commentedI just did some testing:
Is the data I get for a node with node ID 2. But how do you get the entity out of that info?
Comment #3
kreynen CreditAttribution: kreynen commentedFor CiviCRM Multiday Event I added a custom function to add the term id of the node when the date is part of the a field collection.
http://drupalcode.org/project/civicrm_multiday_event.git/blob/refs/heads...
Comment #4
phoenix CreditAttribution: phoenix commented@tim.plunkett I would just like to color a block on the calendar based on the entity reference. So doesn't depend on a part of it, just the nid or uuid is enough. In my case both entities are nodes. So based on the nid found in the entityreference field would be enough to set the color.
Comment #5
phoenix CreditAttribution: phoenix commentedSorry, added a tag by mistake. Removing the tag.
Comment #6
phoenix CreditAttribution: phoenix commentedI have looked into the code for node colors, taxonomy colors, og colors.
But this entity reference thing is difficult. How to make a listing of all possible references?
I could make some code to work in my case, but how to make it generic?
What if I would make a start with a generic solution to associate a color based on the id of the referenced entity?
Do I need to check every entity for an entityreference field? Then check to which entities they are referencing? Then show all these entities listings to associate with a color? (A bit like a vocabulary, then showing terms to associate a color?).
Or is there another way to make this work?
Comment #7
bkosborneOne way to do this (by extending the colors module) is to allow each node of a given content type to be given a color.
Now that each node can be given a color, you would expose a form on the vertical tab when editing the content type to chose which entity reference field to apply it to. That's probably done in a different module.
You could implement hook_fullcalendar_classes, look at the given entity, and determine if you should add the coloring class to it.
The downside to this approach is that if you have a ton of nodes, that colors form for assigning colors to each node would become way too large. However that's already the case when assigning colors to taxonomy terms and users... there could be thousands. In the case of having so many potential subjects to apply a color, it would make more sense to place the color assignment on the node edit form.
Comment #8
bkosborneThough a much faster/easier approach is to implement hook_fullcalendar_classes, add a class that contains the ID of the referenced entity, and then just add your own CSS to theme it :)
Comment #9
kreynen CreditAttribution: kreynen commentedhook_fullcalendar_classes is the what was suggested in #3 too
Comment #10
milos.kroulik CreditAttribution: milos.kroulik commentedI believe this is duplicate of https://drupal.org/node/2044395
Comment #11
bkosborneI don't think so. The other issue is for entity reference taxonomy terms. This is for entity reference fields of any type.