I have a Drupal View based on one entity that is pulled from another database (it is a CiviCRM entity pulled into Drupal with the help of CiviCRM Entity
Drupal module).
One of the fields I use is an array field (let's say it's called arrayfield
), which outputs an array like item1, item2, item3
(items are strings) for each instance of the entity. The number of items (that is, the array length of arrayfield
) is limited to a certain number for each instance of the entity.
Now I want to have each of these item
s available as a separate field in the Drupal View. Field name should be item1
etc. and field value should be 1
if item1
is existent in this arrayfield
's array, and 0
if item1
is not existent there.
How do I achieve this? I though of several solutions:
- somehow including a function inside Drupal Views that will "explode" my array field into several other fields. I know the functionality is there, because right now I can filter
arrayfield
for specific values with a normal Drupal Views filter - that is, Drupal Views is searching through the arrayfield
array. I can just not access this functionality for my purpose.
- using
PHP Views
-- I read it should not be used due to security reasons: https://ohthehugemanatee.org/blog/2013/12/26/44497-people-are-wrong-how-to-never-use-views-php/
as well as performance: https://www.drupal.org/project/views_php
- Creating a custom little Drupal module for splitting
arrayfield
. The problem is that it seems to create a new table with the split values. But I need to be able to access these values in a Drupal View based on an existing entity. That is, I cannot work with random tables because they will not be available in my Drupal view's Relationships
.
- Cloning the existing entity (in CiviCRM database), splitting the values of
arrayfield
, creating a new entity attribute for each of these values (0
or 1
again), creating a relation between original entity and new entity, making the new entity available in Drupal via CiviCRM Entity
module, and including the new entity in Drupal views via Relationships
. The problem is, we would prefer not to change the original database too much, if possible.
- Unfortunately, it seems to be impossible to clone and change the entity on the Drupal side only, as
CiviCRM Entity
module does not copy the entity into Drupal, but only pulls the information from the original database.
Does anyone have a hint?
The need to split an array doesn't seem so complex to me honestly, so there should be a simpler solution to this inside Drupal Views than creating additional entities. It is only a question of display, nearly, as no additional information is required.
Usecase/Goal:
I have a system with one Drupal and one CiviCRM database, that I want to complement with some statistics. I created a Drupal View for each statistical question, which pulls its information from the CiviCRM database with the help of CiviCRM Entity
Drupal module. But the data (which is multiple choice options) comes in as an array of options. I cannot properly count the options with Drupal Views if they are not available as single values.