Suppose I use views where I set contextual filter to filter by NID and I use Provide default value - Content ID from URL. This is perfectly working on node view or node edit pages but in case the view is being rendered for ajax callback where the ajax callback is called from node/edit page no NID value is provided. This is due to a fact that the url of such a callback is system/ajax and Provide default value - Content ID from URL is trying to get node with menu_get_object from url (implemented in views_plugin_argument_default_node->get_argument()).
One of concrete cases where this issue is happening is when I add Entity Reference field to the node then set number of values to unlimited and use ENTITY SELECTION
mode: Views: Filter by an entity reference view. Then every time when "Add another item" is pressed the view display return 0 results because Content ID from URL does not provide NID value. The issue is also documented on entity reference module here:
I made a bit of research because I was not sure if this is the problem of views module or if it is a problem of entity reference module or even the drupal ajax. Issue number 1 is that the system/ajax callback does not provide any data about node when is called from node/edit form. Only way to get the node info is from Header data for ajax callback from referer value. With the current implementation of views and ajax I think this issue should be addressed in this module.
I am attaching patch that alters get_argument() method of views_plugin_argument_default_node class where I added functionality to retrieve node NID value from referer value from header of ajax callback.
FAILED: [[SimpleTest]]: [MySQL] Failed to run tests: tests were executed, but no results were found. View