Great job on all the updates.

Taxonomy Stripes does not see the term_reference field attached to the Entity because in field_get_items(), the first parameter being passed is the base table rather than the entity_type. The symptom will be that the stripes do not appear.

The attached patch is small and fixes the issue. It is the same issue as another patch I provided just in a different place.

Please review and merge so we can put this easy fix behind us.

Cheers,

Alex

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

Status: Needs review » Postponed (maintainer needs more info)

I need information about how to reproduce a problem because this works fine for me.

attiks’s picture

Assigned: alex.neblett » Unassigned
Status: Postponed (maintainer needs more info) » Active

Regarding the problem of alex: field_get_items expects an entity type as first parameter, so $this->view->base_table is wrong.

But both the original code and the patch above don't work for taxonomy fields defined on an other entity (which is my use case), why don't you use the field value from $result->$row?

To reproduce create a node type (A), with a node reference to another node type (B), add a field_collection (C) to this type.
A has a taxonomy field
C has a multi-value date field

attiks’s picture

Ugly code but it works:

  function calendar_taxonomy_stripe(&$result) {
    $colors = isset($this->options['colors']['calendar_colors_taxonomy']) ? $this->options['colors']['calendar_colors_taxonomy'] : array();
    if (empty($colors)) {
      return;
    }

    $entity = $result->entity;
    $term_field_name = 'field_' . $this->options['colors']['taxonomy_field'];
    $term = $result->row->{$term_field_name}[0]['raw']['taxonomy_term'];
    if (!array_key_exists($term->tid, $colors) || $colors[$term->tid] == CALENDAR_EMPTY_STRIPE) {
      return;
    }
    $result->stripe[] = $colors[$term->tid];
    $result->stripe_label[] = $term->name;
/*
    if ($terms_for_entity = field_get_items($this->view->base_table, $entity, $term_field_name)) {
      foreach ($terms_for_entity as $delta => $item) {
        $term_for_entity = taxonomy_term_load($item['tid']);
        if (!array_key_exists($term_for_entity->tid, $colors) || $colors[$term_for_entity->tid] == CALENDAR_EMPTY_STRIPE) {
          continue;
        }
        $result->stripe[] = $colors[$term_for_entity->tid];
        $result->stripe_label[] = $term_for_entity->name;
      }
    }
*/
    return;
  }
johnv’s picture

IMO the initial patch is correct and needed.
I did a test for nodes, users, commerce products (as an example of 'other' Entities). I added dates and terms to them, and created a calendar view for each. Nodes and Commerce products are OK, but no taxonomy colors on the User page.
The calendar striping does not work when base_table and entity_type are different.

In function pre_render() , the following happens to convert base_table to entity_type:

    $base_tables = date_views_base_tables();
    $this->entity_type = $base_tables[$this->view->base_table];

So, in later code, $this->entity_type must be used everywhere. The patch does that.

johnv’s picture

Component: Code » Legend and striping
Status: Active » Reviewed & tested by the community
johnv’s picture

johnv’s picture

Title: Taxonomy Stripes does not see term_reference field attached to Entity when displaying calendar » No Taxonomy Stripes for terms attached to Entity type or via Relationship
letapjar’s picture

This patch worked for me. I had a calendar based on an entity created with the ECK. Before this patch - there were no stripes at all showing up. Once this patch was applied, the stripes showed up with the correct colors.

Thanks so much for figuring this out- it was driving me nuts!

Please consider rolling this patch into the latest dev.

erwangel’s picture

Issue summary: View changes

#3 worked for me. I don't know if the issue's title reflects the same problem as the solution. My case is dimilar to attiks' (#2) : Node-bundle (type) A references Node-bundle B. The taxonomy term to be "striped" is a field of B, but the base node in calendar is A. So the problem in function calendar_taxonomy_stripe(&$result) is not so the view->base_table or the entity_type, but the $entity and the $term_field_name in this line:
if ($terms_for_entity = field_get_items($this->view->base_table, $entity, $term_field_name))
By default the $entity as well as the $term_field_name correspond to node A, and this way it misses the taxonomy field which is part of node B. Fortunately, this info is present inside the $result->row. That's what attiks uses in #3.
I don't see how the solution could be proper. In views>format>calendar-entities we can set a relation, but if we set the relation to the B's taxonomy field then nothing shows anymore in the calendar because this setting acts globally on all display fields not only the taxonomy one. so what we need is a relation there to precise which taxonomy field we want to colorize.

apsylone’s picture

#3 Worked for me too !

This should really be integrated in a -dev version !

ron_s’s picture

I tried both the original patch from @alex.neblett and the #3 patch suggested by @attiks, and the #3 patch is the one that works for me.

I have a content type called "program" that can have one or more "event" content types attached to it via reference field. The taxonomy for the legend striping is on the program, not on the event. The event is the content type that has the date field.

The calendar is based off of the events, but has a relationship to program so the taxonomy can be pulled in. I do see that at the top of the "Calendar Entities | Settings" in Views there is the option to set a relationship. However if I try to do that, the calendar returns no events.

Attached is a formal patch of @attiks' code against 7.x-3.x-dev. I don't know if this works for other calendar striping options, but does fix this entity relationship problem.

ron_s’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.68 KB

After further testing, the patch does not work correctly when a calendar event has multiple taxonomy stripes. The reason for the foreach ($terms_for_entity as $delta => $item) { loop in the calendar_taxonomy_stripe function is to render each stripe associated with the event.

I've modified the patch in #11 to allow for multiple taxonomy stripes. See attached and please review.

Momseekingbalance’s picture

Thanks for the patch! It worked for me!

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I was with @momseekingbalance when we tried out this patch. We were experiencing the same error as described here... a few more details:

We were looking a 7.x site where the Date field that Calendar is based on is part of a multi-field, so to get the Taxonomy for striping (not to mention the event title etc.), you have to use a relationship to the content item. Without this patch, the striping based on taxonomy did not work. With this patch applied, it did work.

As one note though: the Legend block doesn't display. So I suspect that the code that creates the Legend block needs a similar fix. This isn't a huge problem on the site though, since it's relatively easy to create a custom block with a calendar legend in it (it only has a few taxonomy terms in this vocabulary).

So I'm tempted to mark this RTBC, because the patch does fix the striping, but also tempting to mark it Needs Work, because the legend is still broken even with that latest patch.

ugintl’s picture

@ron_s So I should first apply #3 and then your patch?

jhodgdon’s picture

No, #3 was made into a patch file in #11. Then in #12 that patch was revised. So, the recommendation is to use #12.

wylbur’s picture

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for you're patience, I've committed this to the dev branch for the next release.

  • joelpittet committed a5ddab3 on 7.x-3.x authored by ron_s
    Issue #1556676 by ron_s, alex.neblett, johnv, jhodgdon, attiks, KarenS,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Uv516’s picture

Please... - I still have this issue.
Drupal 7.75
Calendar 7.x-3.6
All other modules is up to date.
I have inserted a term-field, but no colorbox.