1

I have an entity reference field that is inside of a field_collection (D8) and I need to alter it's views arguments during ajax load to pass in the value from a preceding field on the host entity. I have everything working except I am not sure how to change the handler_settings on the field_collections entity reference.

Node
  - field_a: contains argument to pass to field_c
  - field_b: field_collection_item
    - field_c: entity reference field using a view for it's available options. Need to pass in views arguments to this field's handler_settings whenever I ajax load field_b.

So far I have field_b properly ajaxing in, but I am not sure how to alter the handler_settings. I have this to obtain the current handler_settings:

  $field_name = 'field_c';
  $bundle_fields = \Drupal::getContainer()->get('entity_field.manager')->getFieldDefinitions('field_collection_item', 'field_b');
  $field_definition = $bundle_fields[$field_name];
  $field_project_handler_settings = $field_definition->getSetting('handler_settings');

The output of $field_project_handler_settings is:

kint output

Thanks in advance!

4
  • After thinking about this some more I might have found a solution. I am going the route of creating a custom field type for this field where I might be able to override the argument settings when I extend the EntityReferenceItem class to create my field type. Anyone have an opinion on this idea? Mar 15, 2016 at 22:03
  • Also, I now thought about something maybe even simpler, provide a custom token that passes the needed value through the arguments. I am already running a patch on Drupal core to allow for this. Trying this first. Mar 15, 2016 at 22:20
  • Well, while coding this token module I realized that the entity is not yet created so the token value won't likely exist. I need to do the field type I think. Trying that now. Mar 15, 2016 at 22:35
  • Hi @nicholas.alipaz Have you found solution to change field handler_settings within hook_form_alter? I have to create new Widget and have done modifications in that widget. To achieve this drupal.stackexchange.com/questions/258138/… Please answer / suggest if you are able to alter settings. Thanks :)
    – jas
    Mar 22, 2018 at 7:07

0

Your Answer

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

Browse other questions tagged or ask your own question.