Problem/Motivation

Activity entity currently doesn't declare views data handler.

Proposed resolution

Implement views data handler for activity entity. Rely on EntityViewsData for sane defaults and build on top of that. See what data and which views handlers activity used in D7 (files in modules/crm_core_activity/views). Goal of this issue is to achieve feature-parity with D7 version.

Patch will be complete when:
- we have feature parity with D7 version
- D7 code is either ported or removed
- we have test coverage

Comments

slashrsm created an issue. See original summary.

slashrsm’s picture

Title: Provide views support for contacts » Provide views support for activity
CTaPByK’s picture

Assigned: Unassigned » CTaPByK

This issue is similar to what i'm working right now, to provide views support for contact, so i will take this one.

CTaPByK’s picture

Status: Active » Needs review
StatusFileSize
new19.38 KB

Here is new patch with some cleanup and new views support for activity.

sanja_m’s picture

Status: Needs review » Reviewed & tested by the community

It seems ok.

slashrsm’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/modules/crm_core_activity/src/ActivityViewsData.php
    @@ -0,0 +1,109 @@
    +    // View, Edit and Delete links of activity.
    +    $data['crm_core_activity']['view_crm_activity'] = array(
    +      'field' => array(
    +        'title' => t('Link'),
    +        'help' => t('Provide a simple link to the activity.'),
    +      ),
    +    );
    +
    +    $data['crm_core_activity']['edit_crm_activity'] = array(
    +      'field' => array(
    +        'title' => t('Edit link'),
    +        'help' => t('Provide a simple link to edit the activity.'),
    +      ),
    +    );
    +    $data['crm_core_activity']['delete_crm_activity'] = array(
    +      'field' => array(
    +        'title' => t('Delete link'),
    +        'help' => t('Provide a simple link to delete the activity.'),
    +      ),
    +    );
    

    This 3 fields don't make sense any more as we removed their handlers (since core provides same functionality in a different way).

  2. +++ b/modules/crm_core_activity/src/ActivityViewsData.php
    @@ -0,0 +1,109 @@
    +    // Expose the creator uid.
    +    $data['crm_core_activity']['uid'] = array(
    +      'title' => t('Author'),
    +      'help' => t('Relate CRM Core Activities to the user who created it.'),
    +      'field' => array(
    +        'id' => 'numeric',
    +        'click sortable' => TRUE,
    +      ),
    +      'argument' => array(
    +        'id' => 'numeric',
    +      ),
    +      'filter' => array(
    +        'id' => 'numeric',
    +      ),
    +      'sort' => array(
    +        'id' => 'standard',
    +      ),
    +      'relationship' => array(
    +        'id' => 'standard',
    +        'label' => t('Author'),
    +        'base' => 'users',
    +        'base field' => 'uid',
    +      ),
    +    );
    

    This field is also provided by core.

  3. +++ b/modules/crm_core_activity/src/ActivityViewsData.php
    @@ -0,0 +1,109 @@
    +    // Integration with Drupal search index.
    +    $data['search_index']['table']['join']['crm_core_activity'] = array(
    +      'left_field' => 'activity_id ',
    +      'field' => 'sid',
    +    );
    +
    +    $data['search_total']['table']['join']['crm_core_activity'] = array(
    +      'left_table' => 'search_index',
    +      'left_field' => 'word',
    +      'field' => 'word',
    +    );
    +
    +    $data['search_dataset']['table']['join']['crm_core_activity'] = array(
    +      'left_table' => 'search_index',
    +      'left_field' => 'sid',
    +      'field' => 'sid',
    +      'extra' => 'search_index.type = search_dataset.type',
    +      'type' => 'INNER',
    +    );
    

    We won't be using core search.

  4. +++ b/modules/crm_core_activity/src/ActivityViewsData.php
    @@ -0,0 +1,109 @@
    +    $data['crm_core_activity_type']['table']['join'] = array(
    +      'crm_core_activity' => array(
    +        'left_field' => 'type',
    +        'field' => 'type',
    +      ),
    +    );
    +
    +    $data['crm_core_activity_type']['activity_string'] = array(
    +      'field' => array(
    +        'title' => t('Activity string'),
    +        'help' => t('Text describing the relationship between the contact and this activity.'),
    +        'id' => 'standard',
    +      ),
    +    );
    

    And types are not in SQL any more so we can't join.

  5. +++ b/modules/crm_core_activity/src/Entity/Activity.php
    @@ -29,6 +29,7 @@ use Drupal\crm_core_contact\ContactInterface;
    + *     "views_data" = "Drupal\crm_core_activity\ActivityViewsData",
    

    Comments above make ActivityViewsData unneeded so we use EntityViewsData here instead.

    At the end of this comment block there is a @todo which can be removed with this patch.

  6. +++ b/tests/modules/crm_core_tests/crm_core_tests.info.yml
    @@ -0,0 +1,9 @@
    +  - crm_core
    

    This module should depend on crm_core_activity too.

CTaPByK’s picture

Status: Needs work » Needs review
StatusFileSize
new6.85 KB
new15.95 KB

Here is new patch with fixes requested by latest review.

sanja_m’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

  • slashrsm committed a893771 on 8.x-1.x authored by CTaPByK
    Issue #2691437 by CTaPByK, slashrsm, sanja_m: Provide views support for...

  • slashrsm committed a893771 on 8.x-2.x authored by CTaPByK
    Issue #2691437 by CTaPByK, slashrsm, sanja_m: Provide views support for...
mbovan’s picture

Status: Active » Fixed

I guess this should be fixed.

CTaPByK’s picture

Assigned: Unassigned » CTaPByK

Yes this is fixed but somehow after commit it changed status to active and assigned to unassigned.

Status: Fixed » Closed (fixed)

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