Answers.Body: <p>Partial answer.</p>
  
  <p>I tried CiviCRM Entities and the Expose Civi tables to Views projects.
  Entities doesn't seem to fit my needs and did not appear to add the tables I needed to Views.</p>
  
  <p>Expose tables to Drupal Views would have worked but was throwing errors and still required me to write a small custom module.</p>
  
  <p>I think this stuff should be in core anyway, so I started down that route.</p>
  
  <p>In the civicrm.core.inc file I started to play around with the civicrm_file table.</p>
  
  <p><strong>I told Views about the table and defined all pertinent columns: id, entity_id, uploaded date, description and mime type.</strong></p>
  
  <pre><code>/*
       * Add support for CiviCRM attachments
       */
       /*
       * Add CiviCRM file table
       */  
        $data['civicrm_file']['table']['group'] = t('CiviCRM Files');
  
        $data['civicrm_file']['table']['base'] = array(
          // 
          'field' =&gt; 'id',
          'title' =&gt; t('CiviCRM Files'),
          'help' =&gt; t("View displays CiviCRM Attachments"),
        );
        //Numeric File ID
        $data['civicrm_file']['id'] = array(
          'title' =&gt; t('File ID'),
          'help' =&gt; t('The numeric ID of the Attachment'),
          'field' =&gt; array(
            'handler' =&gt; 'views_handler_field_numeric',
            'click sortable' =&gt; TRUE,
          ),
          'argument' =&gt; array(
            'handler' =&gt; 'views_handler_argument_numeric',
            'numeric' =&gt; TRUE,
          ),
          'filter' =&gt; array(
            'handler' =&gt; 'views_handler_filter_numeric',
          ),
          'sort' =&gt; array(
            'handler' =&gt; 'views_handler_sort',
          ),
        );
          //URI
        $data['civicrm_file']['uri'] = array(
          'title' =&gt; t('URI'),
          'help' =&gt; t('The URI of the Attachment'),
          'field' =&gt; array(
            'handler' =&gt; 'views_handler_field_file',
            'click sortable' =&gt; TRUE,
          ),
        );
        //File Upload Date
        $data['civicrm_file']['upload_date'] = array(
          'title' =&gt; t('File Upload Date'),
          'help' =&gt; t('The date the Attachment was uploaded'),
          'field' =&gt; array(
            'handler' =&gt; 'civicrm_handler_field_datetime',
            'click sortable' =&gt; TRUE,
          ),
          'filter' =&gt; array(
            'handler' =&gt; 'civicrm_handler_filter_datetime',
          ),
          'sort' =&gt; array(
            'handler' =&gt; 'civicrm_handler_sort_date',
          ),
        );
        //File Description
        $data['civicrm_file']['description'] = array(
          'title' =&gt; t('Description'),
          'help' =&gt; t('The description of the Attachment'),
          'field' =&gt; array(
            'handler' =&gt; 'civicrm_handler_field',
            'click sortable' =&gt; TRUE,
          ),
          'argument' =&gt; array(
            'handler' =&gt; 'views_handler_argument_string',
            'numeric' =&gt; TRUE,
          ),
          'filter' =&gt; array(
            'handler' =&gt; 'views_handler_filter_string',
          ),
          'sort' =&gt; array(
            'handler' =&gt; 'views_handler_sort',
          ),
        );
        //File Mime Type
        $data['civicrm_file']['mime_type'] = array(
          'title' =&gt; t('Mime Type'),
          'help' =&gt; t('The mime type of the Attachment'),
          'field' =&gt; array(
          'handler' =&gt; 'views_handler_field_file_filemime',
          'click sortable' =&gt; TRUE,
         ),
       );
  </code></pre>
  
  <p><strong>Then added the join in the Activities section.</strong></p>
  
  <pre><code> /*
    //TABLE JOINS FOR CIVICRM ACTIVITIES GO HERE!
      /*
       * Add joins for CiviCRM attachments
       */
    $data['civicrm_file']['table']['join']['civicrm_activity'] = array(
      'left_table' =&gt; 'civicrm_entity_file',
      'left_field' =&gt; 'file_id',
      'field' =&gt; 'id',
    );
  
    $data['civicrm_entity_file']['table']['join']['civicrm_activity'] = array(
      // Directly links to file table
      'left_field' =&gt; 'id',
      'field' =&gt; 'entity_id',
      'extra' =&gt; array(
        array(
          'field' =&gt; 'entity_table',
          'value' =&gt; 'civicrm_activity',
          'numeric' =&gt; FALSE,
        ),
      ),
    );
  </code></pre>
  
  <p>I'm sure my code can use some clean up as that's not my bag, but when I create a View of Activities, I now get these options:</p>
  
  <p><img src="https://i.sstatic.net/No6Fi.png" alt="Attachments added to Group List"></p>
  
  <p><img src="https://i.sstatic.net/6CE5A.png" alt="Attachments added to Field list"></p>
  
  <p><strong>And this is the resuult:</strong>
  <img src="https://i.sstatic.net/4qAz7.png" alt="Results"></p>
  
  <p>Struggling to form the url correctly.</p>
  
  <p>I'd like to use the same handler that Civi uses for custom file fields (civicrm_handler_field_custom_file or the non-custom alternative, civicrm_handler_field_file) but when I try either of those, I get a broken handler error.</p>
  
  <p>Those handlers pass the entity id as well as the file id into the url.  So the url is formed like:</p>
  
  <p>localhost/civicrm/file?id=[file_id]&amp;eid=[entity_id]#</p>
  
  <p>The error has to do with the entity_id column referenced in those handlers.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-11T14:22:56.373Z
Answers.Text: I ended up using custom file fields for attachments which were much easier to manipulate in our use case.
Answers.UserDisplayName: pmoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T15:28:53.270Z
Answers.LastActivityDate: 2015-06-19T13:44:20.427Z
Answers.LastEditDate: 2015-06-19T13:44:20.427Z
Answers.UserDisplayName: pmoz
Answers.Body: <p>I attended a session yesterday at CiviCon (<a href="https://denver2015.civicrm.org/sessions/civicrmdrupal-integration-showcase" rel="nofollow">https://denver2015.civicrm.org/sessions/civicrmdrupal-integration-showcase</a>; the slides are up already) about exposing more Civi tables to Views.  </p>
  
  <p>CiviCRM Entity 1.x might display the table you need.  CiviCRM Entity 2.x-dev most definitely will.  (<a href="https://www.drupal.org/project/civicrm_entity" rel="nofollow">https://www.drupal.org/project/civicrm_entity</a>)  The session slides have lots of details on installation and use.</p>
  
  <p>A sandbox module is also available to expose the Civi tables to Views (<a href="https://www.drupal.org/sandbox/markusa/2474103" rel="nofollow">https://www.drupal.org/sandbox/markusa/2474103</a>).</p>
  
  <p>The inherent (edited) difference is the sandbox module is just exposing the data to Views. The CiviCRM Entity module will make Civi data available to all of Drupal as entities.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T10:29:49.400Z
Answers.Text: Thanks for the info.
  I've been anxious to wrap my head around this module, but there really isn't much use case or example type stuff out there for it.  I think I'll hold on until 2.0 is released and give it a go.
Answers.UserDisplayName: pmoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T10:33:02.917Z
Answers.Text: By the way, is there a use for both the sandbox module to expose Civi tables to Views and CiviCRM Entity or are they sort of one or the other?
Answers.UserDisplayName: pmoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T15:44:26.180Z
Answers.Text: I think it just depends on what you need. If you're using Entity 2 then you probably don't need the Sandbox. If you don't need Civi data to have the benefit of Drupal entity characteristics, then I imagine the sandbox module will be sufficient and have less overhead.
Answers.UserDisplayName: Allen Hutchison
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T15:06:45.360Z
Answers.LastActivityDate: 2015-04-24T15:43:50.537Z
Answers.LastEditDate: 2015-04-24T15:43:50.537Z
Answers.UserDisplayName: Allen Hutchison
Answers.Body: <p>For a project I have build a Drupal CiviCRM views module which extends the Drupal views module with missing data, such as attachments. You can find this module, which is quite project specific, at <a href="https://github.com/PUMNL/pum_civicrm_views" rel="nofollow">https://github.com/PUMNL/pum_civicrm_views</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T12:47:43.167Z
Answers.LastActivityDate: 2015-04-23T12:47:43.167Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.Body: <p>Update of Partial Answer</p>
  
  <p>Following on from the partial answer i added the following table definition for the entity_file table. 
  This section of code was added just after the definition for the file table (the first bit of the partial answer).  The joins have already been taken care of in the original answer (second bit), this just gives the fields to use to build a working link to download the file</p>
  
  <pre><code>/*
   * Add CiviCRM entity file table
   */  
  $data['civicrm_entity_file']['table']['group'] = t('CiviCRM Entity Files');
  
  $data['civicrm_entity_file']['table']['base'] = array(
    // 
    'field' =&gt; 'id',
    'title' =&gt; t('CiviCRM Entity Files'),
    'help' =&gt; t("View displays CiviCRM Attachments create link to download"),
  );
  //Numeric File ID
  $data['civicrm_entity_file']['id'] = array(
    'title' =&gt; t('Entity File ID'),
    'help' =&gt; t('The numeric ID entity file record of the Attachment'),
    'field' =&gt; array(
      'handler' =&gt; 'views_handler_field_numeric',
      'click sortable' =&gt; TRUE,
    ),
    'argument' =&gt; array(
      'handler' =&gt; 'views_handler_argument_numeric',
      'numeric' =&gt; TRUE,
    ),
    'filter' =&gt; array(
      'handler' =&gt; 'views_handler_filter_numeric',
    ),
    'sort' =&gt; array(
      'handler' =&gt; 'views_handler_sort',
    ),
  );
    //EntityTable
  $data['civicrm_entity_file']['entity_table'] = array(
    'title' =&gt; t('Entity Table'),
    'help' =&gt; t('The content type associated with the attachment'),
    'field' =&gt; array(
      'handler' =&gt; 'civicrm_handler_field',
      'click sortable' =&gt; TRUE,
    ),
  );
  //Entity ID
  $data['civicrm_entity_file']['file_id'] = array(
    'title' =&gt; t('File ID'),
    'help' =&gt; t('FK to the ID of the file in civicrm_file table'),
    'field' =&gt; array(
      'handler' =&gt; 'views_handler_field_numeric',
      'click sortable' =&gt; TRUE,
    ),
  );
  //Entity ID
  $data['civicrm_entity_file']['file_id'] = array(
    'title' =&gt; t('File ID'),
    'help' =&gt; t('FK to the ID of the file in civicrm_file table'),
    'field' =&gt; array(
      'handler' =&gt; 'views_handler_field_numeric',
      'click sortable' =&gt; TRUE,
    ),
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-13T23:41:31.537Z
Answers.Text: Good work!  You should add the changes to github!
Answers.UserDisplayName: pmoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-06T21:04:55.670Z
Answers.Text: had a go at doing this, not sure if it'll work
Answers.UserDisplayName: Bruce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-13T16:21:05.330Z
Answers.LastActivityDate: 2016-04-13T19:41:05.310Z
Answers.LastEditDate: 2016-04-13T19:41:05.310Z
Answers.UserDisplayName: Bruce
Answers.Body: <p>The link is in the civicrm_entity_file table, which links the activity and the attachment. The attachment itself is in the civicrm_file table.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T10:10:30.873Z
Answers.Text: I have those tables in the settings.php file, but can't seem to find them within views.
Answers.UserDisplayName: pmoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T10:40:55.587Z
Answers.Text: Sorry, not too much Views expertise so no idea why they would not show up :-(
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T06:21:45.700Z
Answers.LastActivityDate: 2015-04-23T06:21:45.700Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>Trying to set up an activity view that displays attachments uploaded to activities.</p>
  
  <p>I can't seem to find the field to add.</p>
  
  <p>Any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-23T02:01:58.380Z
Comments.Text: Is it a custom attachments field?
Comments.UserDisplayName: Laryn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-23T10:09:27.220Z
Comments.Text: Not the one I'm starting with.  It is the standard activity attachment.
Comments.UserDisplayName: pmoz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-23T12:41:07.143Z
Comments.Text: I haven't used this functionality but tried a quick install and ran into the same question... Sorry.
Comments.UserDisplayName: Laryn
Tags: <civicase><drupal-views><activities>
Title: How do I add CiviCRM Activity attachment to View
ThreadText: # How do I add CiviCRM Activity attachment to View
  
  (Asked by: username_0 on 2015-04-22)
  
  Trying to set up an activity view that displays attachments uploaded to activities.
  
  I can't seem to find the field to add.
  
  Any ideas?
  
  **Tags:** civicase, drupal-views, activities
  
  > **Comments:**
  > **username_1**: Is it a custom attachments field?  
  > **username_0**: Not the one I'm starting with.  It is the standard activity attachment.  
  > **username_1**: I haven't used this functionality but tried a quick install and ran into the same question... Sorry.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_0 on 2015-06-18. Score: 2 | Accepted answer
  
  Partial answer.
  
  I tried CiviCRM Entities and the Expose Civi tables to Views projects.
  Entities doesn't seem to fit my needs and did not appear to add the tables I needed to Views.
  
  Expose tables to Drupal Views would have worked but was throwing errors and still required me to write a small custom module.
  
  I think this stuff should be in core anyway, so I started down that route.
  
  In the civicrm.core.inc file I started to play around with the civicrm\_file table.
  
  **I told Views about the table and defined all pertinent columns: id, entity\_id, uploaded date, description and mime type.**
  
  ```
  /*
       * Add support for CiviCRM attachments
       */
       /*
       * Add CiviCRM file table
       */  
        $data['civicrm_file']['table']['group'] = t('CiviCRM Files');
  
        $data['civicrm_file']['table']['base'] = array(
          // 
          'field' => 'id',
          'title' => t('CiviCRM Files'),
          'help' => t("View displays CiviCRM Attachments"),
        );
        //Numeric File ID
        $data['civicrm_file']['id'] = array(
          'title' => t('File ID'),
          'help' => t('The numeric ID of the Attachment'),
          'field' => array(
            'handler' => 'views_handler_field_numeric',
            'click sortable' => TRUE,
          ),
          'argument' => array(
            'handler' => 'views_handler_argument_numeric',
            'numeric' => TRUE,
          ),
          'filter' => array(
            'handler' => 'views_handler_filter_numeric',
          ),
          'sort' => array(
            'handler' => 'views_handler_sort',
          ),
        );
          //URI
        $data['civicrm_file']['uri'] = array(
          'title' => t('URI'),
          'help' => t('The URI of the Attachment'),
          'field' => array(
            'handler' => 'views_handler_field_file',
            'click sortable' => TRUE,
          ),
        );
        //File Upload Date
        $data['civicrm_file']['upload_date'] = array(
          'title' => t('File Upload Date'),
          'help' => t('The date the Attachment was uploaded'),
          'field' => array(
            'handler' => 'civicrm_handler_field_datetime',
            'click sortable' => TRUE,
          ),
          'filter' => array(
            'handler' => 'civicrm_handler_filter_datetime',
          ),
          'sort' => array(
            'handler' => 'civicrm_handler_sort_date',
          ),
        );
        //File Description
        $data['civicrm_file']['description'] = array(
          'title' => t('Description'),
          'help' => t('The description of the Attachment'),
          'field' => array(
            'handler' => 'civicrm_handler_field',
            'click sortable' => TRUE,
          ),
          'argument' => array(
            'handler' => 'views_handler_argument_string',
            'numeric' => TRUE,
          ),
          'filter' => array(
            'handler' => 'views_handler_filter_string',
          ),
          'sort' => array(
            'handler' => 'views_handler_sort',
          ),
        );
        //File Mime Type
        $data['civicrm_file']['mime_type'] = array(
          'title' => t('Mime Type'),
          'help' => t('The mime type of the Attachment'),
          'field' => array(
          'handler' => 'views_handler_field_file_filemime',
          'click sortable' => TRUE,
         ),
       );
  
  ```
  
  **Then added the join in the Activities section.**
  
  ```
   /*
    //TABLE JOINS FOR CIVICRM ACTIVITIES GO HERE!
      /*
       * Add joins for CiviCRM attachments
       */
    $data['civicrm_file']['table']['join']['civicrm_activity'] = array(
      'left_table' => 'civicrm_entity_file',
      'left_field' => 'file_id',
      'field' => 'id',
    );
  
    $data['civicrm_entity_file']['table']['join']['civicrm_activity'] = array(
      // Directly links to file table
      'left_field' => 'id',
      'field' => 'entity_id',
      'extra' => array(
        array(
          'field' => 'entity_table',
          'value' => 'civicrm_activity',
          'numeric' => FALSE,
        ),
      ),
    );
  
  ```
  
  I'm sure my code can use some clean up as that's not my bag, but when I create a View of Activities, I now get these options:
  
  ![Attachments added to Group List](https://i.sstatic.net/No6Fi.png)
  
  ![Attachments added to Field list](https://i.sstatic.net/6CE5A.png)
  
  **And this is the resuult:**
  ![Results](https://i.sstatic.net/4qAz7.png)
  
  Struggling to form the url correctly.
  
  I'd like to use the same handler that Civi uses for custom file fields (civicrm\_handler\_field\_custom\_file or the non-custom alternative, civicrm\_handler\_field\_file) but when I try either of those, I get a broken handler error.
  
  Those handlers pass the entity id as well as the file id into the url. So the url is formed like:
  
  localhost/civicrm/file?id=[file\_id]&eid=[entity\_id]#
  
  The error has to do with the entity\_id column referenced in those handlers.
  
  > **Comments:**
  > **username_0**: I ended up using custom file fields for attachments which were much easier to manipulate in our use case.  
  
  ---
  
  ### Answer by username_2 on 2015-04-23. Score: 3
  
  I attended a session yesterday at CiviCon (<https://denver2015.civicrm.org/sessions/civicrmdrupal-integration-showcase>; the slides are up already) about exposing more Civi tables to Views.
  
  CiviCRM Entity 1.x might display the table you need. CiviCRM Entity 2.x-dev most definitely will. (<https://www.drupal.org/project/civicrm_entity>) The session slides have lots of details on installation and use.
  
  A sandbox module is also available to expose the Civi tables to Views (<https://www.drupal.org/sandbox/markusa/2474103>).
  
  The inherent (edited) difference is the sandbox module is just exposing the data to Views. The CiviCRM Entity module will make Civi data available to all of Drupal as entities.
  
  > **Comments:**
  > **username_0**: Thanks for the info. I've been anxious to wrap my head around this module, but there really isn't much use case or example type stuff out there for it.  I think I'll hold on until 2.0 is released and give it a go.  
  > **username_0**: By the way, is there a use for both the sandbox module to expose Civi tables to Views and CiviCRM Entity or are they sort of one or the other?  
  > **username_2**: I think it just depends on what you need. If you're using Entity 2 then you probably don't need the Sandbox. If you don't need Civi data to have the benefit of Drupal entity characteristics, then I imagine the sandbox module will be sufficient and have less overhead.  
  
  ---
  
  ### Answer by username_3 on 2015-04-23. Score: 2
  
  For a project I have build a Drupal CiviCRM views module which extends the Drupal views module with missing data, such as attachments. You can find this module, which is quite project specific, at <https://github.com/PUMNL/pum_civicrm_views>
  
  
  ---
  
  ### Answer by username_4 on 2016-04-13. Score: 2
  
  Update of Partial Answer
  
  Following on from the partial answer i added the following table definition for the entity\_file table.
  This section of code was added just after the definition for the file table (the first bit of the partial answer). The joins have already been taken care of in the original answer (second bit), this just gives the fields to use to build a working link to download the file
  
  ```
  /*
   * Add CiviCRM entity file table
   */  
  $data['civicrm_entity_file']['table']['group'] = t('CiviCRM Entity Files');
  
  $data['civicrm_entity_file']['table']['base'] = array(
    // 
    'field' => 'id',
    'title' => t('CiviCRM Entity Files'),
    'help' => t("View displays CiviCRM Attachments create link to download"),
  );
  //Numeric File ID
  $data['civicrm_entity_file']['id'] = array(
    'title' => t('Entity File ID'),
    'help' => t('The numeric ID entity file record of the Attachment'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'numeric' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
    //EntityTable
  $data['civicrm_entity_file']['entity_table'] = array(
    'title' => t('Entity Table'),
    'help' => t('The content type associated with the attachment'),
    'field' => array(
      'handler' => 'civicrm_handler_field',
      'click sortable' => TRUE,
    ),
  );
  //Entity ID
  $data['civicrm_entity_file']['file_id'] = array(
    'title' => t('File ID'),
    'help' => t('FK to the ID of the file in civicrm_file table'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
  );
  //Entity ID
  $data['civicrm_entity_file']['file_id'] = array(
    'title' => t('File ID'),
    'help' => t('FK to the ID of the file in civicrm_file table'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
  );
  
  ```
  
  > **Comments:**
  > **username_0**: Good work!  You should add the changes to github!  
  > **username_4**: had a go at doing this, not sure if it'll work  
  
  ---
  
  ### Answer by username_5 on 2015-04-23. Score: 1
  
  The link is in the civicrm\_entity\_file table, which links the activity and the attachment. The attachment itself is in the civicrm\_file table.
  
  > **Comments:**
  > **username_0**: I have those tables in the settings.php file, but can't seem to find them within views.  
  > **username_5**: Sorry, not too much Views expertise so no idea why they would not show up :-(  
  
  ---
  
  