0

I need to add in the current $form_state into the ViewsSelection. I have copied the file /core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php to /modules/custom/fsed_entry/fsed_project_entity_reference_options/src/Plugin/EntityReferenceSelection/ProjectsSelection.php where I have the file overriding views' implementation. However, I can't seem to figure out how to get $form_state into my variables so that I can use a value from another form element. I have been trying to experiment with FormCache but I have not been successful. Any ideas on best approach here?

For background, I need the $form_state because the field that is being rendered (and this plugin is used on) here was ajaxed in and I want to pass in a value that I can add onto the handler_settings -> view -> arguments that this plugin uses.

1 Answer 1

1

There is no form state, at least not with autocomplete. And since the same code is designed to work with autocomplete and other widgets, it can't rely on form state anywhere.

If you have autocomplete you can possibly pass in the settings in the entity_autocomplete form element which should be passed to your plugin. Not sure about other widgets, you might need your own widget to be able to do that.

2
  • Thanks so much for answering Berdir. I am actually using the select list widget but it works of some of the same stuff as autocomplete so your comments certainly make sense. Do you think that using FormCache might allow me to retrieve the cached form state from the current user? I mean we have $current_user and we also can add in the FormCacheInterface I am just not sure if I would be chasing unicorns if I try it. Commented Mar 17, 2016 at 16:33
  • Reading your comment again I am kind of understanding what you are describing now. I could definitely add that data onto the element before it is sent. I might have to change to autocomplete or create a new select widget that is more similar to the autocomplete perhaps. Commented Mar 17, 2016 at 17:12

Your Answer

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

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