1

I have a custom entity "Matching" with a multi value field entity reference jobs that references a node of type job.

function custom_alters_entity_property_info_alter(&$info) {
  $info['node']['properties']['referencing_matching'] = array(
    'label' => t('Referencing matching'),
    'type' => "entities",
    'description' => t("Matchings referecing a job"),
    'getter callback' => 'get_referencing_matching'
  );
}

function referencing_matching($node) {
  if($node->type == "job"){
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'matching')
          ->fieldCondition('field_job_id', 'target_id', $node->nid, '=');
    $result = $query->execute();
    if ($result) {
      return $result;
    }
}

the "getter callback" isn't expecting an id rather than an array

1 Answer 1

2

It looks like you are trying to add a multi-valued entity reference property to a standard node entity. If that's the case, I think you first need to declare the property as multi-valued in hook_entity_info_alter() via the 'type' entry:

$info['node']['properties']['referencing_matching'] = array(
  'label' => t('Referencing matching'),
  'type' => 'list<matching>',
  'description' => t("Matchings referecing a job"),
  'getter callback' => 'get_referencing_matching'
);

See the hook_entity_property_info() notes for more on that.

Then, in the getter callback I believe you need to return a list of entity ids, something like:

if ($node->type == "job"){
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'matching')
        ->fieldCondition('field_job_id', 'target_id', $node->nid, '=');
  $result = $query->execute();
  if (!empty($result['matching'])) {
    return array_keys($result['matching']);
  }
}

I have not tested that specific code, but this was the pattern that I used in a similar example of my own.

Your Answer

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

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