Answers.Body: <p>On a development server, I edited sites/all/modules/civicrm/drupal/modules/views/components/civicrm.core.inc.</p>
  
  <p>In the Tag section, I added:</p>
  
  <pre><code>$data['civicrm_tag']['table']['join']['civicrm_case'] = array(
      'left_table' =&gt; 'civicrm_entity_tag',
      'left_field' =&gt; 'tag_id',
      'field' =&gt; 'id',
    );
  </code></pre>
  
  <p>and</p>
  
  <pre><code> $data['civicrm_entity_tag']['table']['join']['civicrm_case'] = array(
      // Directly links to tag table
      'left_field' =&gt; 'id',
      'field' =&gt; 'entity_id',
      'extra' =&gt; array(
        array(
          'field' =&gt; 'entity_table',
          'value' =&gt; 'civicrm_case',
          'numeric' =&gt; FALSE,
        ),
      ),
    );
  </code></pre>
  
  <p>After that, I was able to filter by case tags.</p>
  
  <p>Would this have any unforeseen ramifications?  Does this cover all of my bases?</p>
  
  <p>Would this be best put into a separate custom module?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-16T20:26:03.583Z
Answers.Text: If this does prove to add the required without creating other problems then best to provide as a patch to JIRA I think
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-15T22:20:19.437Z
Answers.LastActivityDate: 2015-06-15T22:27:31.873Z
Answers.LastEditDate: 2015-06-15T22:27:31.873Z
Answers.UserDisplayName: pmoz
Body: <p>We are trying to achieve a hierarchical approach to some of our case types by using case tags.</p>
  
  <p>It works great on the back-end, but if I try to filter a view by the case tag, I get no results.</p>
  
  <p>In the View UI, I add a filter of CiviCRM tags, see the case tags in the list, but if I select any of them, I get no results.</p>
  
  <p>I've tried with tags attached to contacts, cases, attachments and activities.  The only one that appears to work is when the tag is attached to a contact.</p>
  
  <p>Since Smart Groups don't appear to function correctly in Views either, this functionality would be very useful.</p>
  
  <p>Tables look good, view appears to be set up correctly.  Tags is available as a field and I can see the correct Case Tags in the list of available tags.</p>
  
  <p>I brought this issue up before, but have no resolution yet.  </p>
  
  <p>Here is a link to the old issue:
  <a href="http://forum.civicrm.org/index.php/topic,35100.0.html" rel="nofollow">Case Tags in View</a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T08:04:01.447Z
Comments.Text: I suspect this is new code required for the civi-views module.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T11:18:38.033Z
Comments.Text: Have you tried the relationship option in the views module? In your view you can define relationship between entities. In your case you probably need Tag, TagEntity and Case.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T11:48:07.300Z
Comments.Text: Can't find Tag and TagEntity relationships in Views UI to add them.  I'll poke around some more.
Comments.UserDisplayName: pmoz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T20:09:15.307Z
Comments.Text: Jaap's comment made me wonder what civi component your view is based on? Case, Activity, Contact?
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T20:49:36.510Z
Comments.Text: I've tried cases and contacts.  I got the activity tag to work by creating an activity view, but not the case or attachment tags.  But no matter which component the view is built on, I can't see Tag or EntitiyTag in the relationship UI.
Comments.UserDisplayName: pmoz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-15T21:25:14.917Z
Comments.Text: In sites/all/modules/civicrm/drupal/modules/views/components/civicrm.core.inc, There is tag section that joins tags to contacts and activities.  I don't see anything about cases and/or attachments.
Comments.UserDisplayName: pmoz
Tags: <activities><civicase><drupal-views><cms-integration>
Title: Tags used for Cases, Activities or Attachments in Drupal Views?
ThreadText: # Tags used for Cases, Activities or Attachments in Drupal Views?
  
  (Asked by: username_0 on 2015-06-14)
  
  We are trying to achieve a hierarchical approach to some of our case types by using case tags.
  
  It works great on the back-end, but if I try to filter a view by the case tag, I get no results.
  
  In the View UI, I add a filter of CiviCRM tags, see the case tags in the list, but if I select any of them, I get no results.
  
  I've tried with tags attached to contacts, cases, attachments and activities. The only one that appears to work is when the tag is attached to a contact.
  
  Since Smart Groups don't appear to function correctly in Views either, this functionality would be very useful.
  
  Tables look good, view appears to be set up correctly. Tags is available as a field and I can see the correct Case Tags in the list of available tags.
  
  I brought this issue up before, but have no resolution yet.
  
  Here is a link to the old issue:
  [Case Tags in View](http://forum.civicrm.org/index.php/topic,35100.0.html)
  
  **Tags:** activities, civicase, drupal-views, cms-integration
  
  > **Comments:**
  > **username_1**: I suspect this is new code required for the civi-views module.  
  > **username_2**: Have you tried the relationship option in the views module? In your view you can define relationship between entities. In your case you probably need Tag, TagEntity and Case.  
  > **username_0**: Can't find Tag and TagEntity relationships in Views UI to add them.  I'll poke around some more.  
  > **username_1**: Jaap's comment made me wonder what civi component your view is based on? Case, Activity, Contact?  
  > **username_0**: I've tried cases and contacts.  I got the activity tag to work by creating an activity view, but not the case or attachment tags.  But no matter which component the view is built on, I can't see Tag or EntitiyTag in the relationship UI.  
  > **username_0**: In sites/all/modules/civicrm/drupal/modules/views/components/civicrm.core.inc, There is tag section that joins tags to contacts and activities.  I don't see anything about cases and/or attachments.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-06-15. Score: 1 | Accepted answer
  
  On a development server, I edited sites/all/modules/civicrm/drupal/modules/views/components/civicrm.core.inc.
  In the Tag section, I added:
  $data['civicrm_tag']['table']['join']['civicrm_case'] = array(
      'left_table' => 'civicrm_entity_tag',
      'left_field' => 'tag_id',
      'field' => 'id',
    );
  
  and
   $data['civicrm_entity_tag']['table']['join']['civicrm_case'] = array(
      // Directly links to tag table
      'left_field' => 'id',
      'field' => 'entity_id',
      'extra' => array(
        array(
          'field' => 'entity_table',
          'value' => 'civicrm_case',
          'numeric' => FALSE,
        ),
      ),
    );
  
  After that, I was able to filter by case tags.
  Would this have any unforeseen ramifications?  Does this cover all of my bases?
  Would this be best put into a separate custom module?
  
  > **Comments:**
  > **username_1**: If this does prove to add the required without creating other problems then best to provide as a patch to JIRA I think  
  
  ---
  
  