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

tim.plunkett’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev

What 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 :)

aspilicious’s picture

I just did some testing:

'field_reference' => 
        array (
          'und' => 
          array (
            0 => 
            array (
              'target_id' => '2',
            ),
          ),

Is the data I get for a node with node ID 2. But how do you get the entity out of that info?

kreynen’s picture

For 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...

phoenix’s picture

Issue tags: +extra information

@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.

phoenix’s picture

Issue tags: -extra information

Sorry, added a tag by mistake. Removing the tag.

phoenix’s picture

I 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?

bkosborne’s picture

One 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.

bkosborne’s picture

Though 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 :)

kreynen’s picture

hook_fullcalendar_classes is the what was suggested in #3 too

milos.kroulik’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

I believe this is duplicate of https://drupal.org/node/2044395

bkosborne’s picture

Status: Closed (duplicate) » Active

I don't think so. The other issue is for entity reference taxonomy terms. This is for entity reference fields of any type.