1

Need a hint. With civicrm_entity (3.5) i haven't the possibility to get multiple items in a views row. So i wrote a custom field and now I want to filter it.

I think this works for the contact type (Organization), but I need to filter the related contacts (Individual) by the attached tags.

if (!empty($this->value)) {
  $configuration = [
    'table' => 'civicrm_entity_tag',
    'field' => 'entity_id',
    'left_table' => 'civicrm_contact', 
    'left_field' => 'id', 
    'operator' => '=',
  ];
  $join = Views::pluginManager('join')->createInstance('standard', $configuration);
  $this->query->addRelationship('civicrm_entity_tag', $join, 'civicrm_contact');
  $this->query->addWhere('AND', 'civicrm_entity_tag.tag_id', $this->value, 'IN');

  dump($query->options['relationship']) // i get 'contact_id_a' thats correct with the relationship, but how can i use it?

}

1 Answer 1

1

After I dig a little bit deeper into views and view some other examples - now it works:

if (!empty($this->value)) {
  $this->ensureMyTable(); // to get the tableAlias
  $configuration = [
    'table' => 'civicrm_entity_tag',
    'field' => 'entity_id',
    'left_table' => $this->tableAlias, // set the table alias
    'left_field' => 'id',
    'operator' => '=',
  ];
  $join = Views::pluginManager('join')->createInstance('standard', $configuration);
  $this->query->addRelationship('civicrm_entity_tag', $join, 'civicrm_contact');
  $this->query->addWhere('AND', 'civicrm_entity_tag.tag_id', $this->value, 'IN');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.