Skip to content
Snippets Groups Projects

array field output handler

Merged JonGold requested to merge JonGold/dataprocessor:arrayoutput into master
1 unresolved thread

Adds a new field output handler to return multi-value fields as an array.

My use case: I have an API that sends event data, but I have a multi-value custom field ("Category") which I used with the "OptionFieldOutputHandler". This would return comma-separated values if multiple categories were selected, but I needed them to be a JSON array.

This handler adds the ability to return arrays of multi-value fields (thanks for the isMultiValue property - seems unused elsewhere but very helpful to me!). You can specify in the configuration if you want to return option values or labels.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
69 public function formatField($rawRecord, $formattedRecord) {
70 $formattedValue = $rawRecord[$this->inputFieldSpec->alias];
71 // Convert from a value-separated string to an array.
72 if (strpos($formattedValue, \CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
73 $formattedValue = explode(\CRM_Core_DAO::VALUE_SEPARATOR, substr($formattedValue, 1, -1));
74 }
75 // Convert to option labels if applicable.
76 if ($this->label_as_value) {
77 $options = $this->inputFieldSpec->getOptions();
78 foreach ($formattedValue as $k => $v) {
79 if (isset($options[$v])) {
80 $formattedValue[$k] = $options[$v];
81 }
82 }
83 }
84 $output = new FieldOutput($rawRecord[$this->inputFieldSpec->alias]);
  • Thanks @JonGold I have added a comment in the code can you have a look at that?

  • JonGold added 1 commit

    added 1 commit

    Compare with previous version

  • Author Reporter

    @jaapjansma ah - I saw that class but it seemed unimplemented so I thought it might be deprecated. I've just modified the PR to use that class.

  • Yes it is/was unimplemented.

  • jaapjansma mentioned in commit 91b38077

    mentioned in commit 91b38077

  • merged

  • Please register or sign in to reply
    Loading