0

I have created a content type called providers and when editting said content types users can fill in extra information related to the content.

I have included said form fields using hook_form_alter, and the appropriate hook for _submit applied with it all working fine (saving to db etc)

Where I am stuck is I can access the data, by loading it via hook_ENTITY_TYPE_load call which allows me to access it in _form_alter but for some reason when viewing the node, I do not see the data.

Is there a specific way of loading external data on top of node object in d8?

below is how i load the data.

/**
* implementation of hook_ENTITY_TYPE_load($entities)
*/
function remittance_providers_node_load(array &$entities) {
  //loop thorough the loaded entities
  foreach ($entities as $key => $entity) {
    // if provider node type is being loaded add our data on top of it.
    if ($entity->bundle() == 'providers') {
      $nid = $entity->id();
      $commission_data = currencyStorage::loadCommission(array("companyID"=>$nid));
      if(count($commission_data)>0){
        foreach ($commission_data as $ckey => $comm) {
          $entities[$key]->commission[$ckey]['amount_from'] = $comm->amount_from;
          $entities[$key]->commission[$ckey]['amount_to'] = $comm->amount_to;
          $entities[$key]->commission[$ckey]['commission'] = $comm->commission;
        }
      }
    }
  }
}

I have installed devel and checked all its phases and I dont see it in there.

  • Are you printing this data in the template? What do you mean when you say you don't see it? – Kevin Jul 26 '17 at 1:59
  • yes I am looking to print it out in a template,but when i go to /devel/node/3 I cannot see the 'commission' data array in the provider entity. In the _form stage i could access the data by doing the following: $node = $form_state->getFormObject()->getEntity(); $node->commission[$i]['amount_from'] etc – Shaksi Jul 26 '17 at 2:49
0

I have found preceding value array with [x-default] shows the values. I presume this has to do with the translation module

function remittance_providers_node_load(array &$entities) {
  //loop thorough the loaded entities
  foreach ($entities as $key => $entity) {
    // if provider node type is being loaded add our data on top of it.
    if ($entity->bundle() == 'providers') {
      $nid = $entity->id();
      $commission_data = currencyStorage::loadCommission(array("companyID"=>$nid));
      if(count($commission_data)>0){
        foreach ($commission_data as $ckey => $comm) {
          $entities[$key]->commission['x-default'][$ckey]['amount_from'] = $comm->amount_from;
          $entities[$key]->commission['x-default'][$ckey]['amount_to'] = $comm->amount_to;
          $entities[$key]->commission['x-default'][$ckey]['commission'] = $comm->commission;
        }
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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