Usually you would add an excluded contextual filter to View of type Content: Nid, and provide a default value like Content ID from URL..

I tried this on my ER View Widget display: it works in the View preview, but doesn't when the modal is opened during the node editing.

How to do this?
This seems very basic functionality: obviously you don't want to add the current entity as a reference to itself.
(Of course this will not work while creating a node)

CommentFileSizeAuthor
#2 custom_formalter.module.txt290 bytestfranz
#2 custom_formalter.info64 bytestfranz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kopeboy’s picture

Issue summary: View changes
tfranz’s picture

You can pass an argument to your views via a hook as described here:
https://www.drupal.org/node/1626668

Simple example:
Create a custom module with the following function:

function custom_formalter_entityreference_view_widget_views_arguments_alter(&$arguments, $context) {
//    drupal_set_message("<pre>".print_r($context)."</pre>"); // Active this line to find your value in the $context-array
  if (empty($arguments)) {
    $arguments[0] = 'all';
  }
  if ($context['values']['nid']){
        $arguments[] = $context['values']['nid'];
  }
}

(Tested with 7.x-2.0-rc6)

komlenic’s picture

The code in #2 essentially worked for me, however, this part:

  if (empty($arguments)) {
    $arguments[0] = 'all';
  }

...didn't logically make sense for my application, and may not for yours either.