I needed get field's value and pass it as contextual filter to "entity reference view" just described as views and contextual filters with entity reference field.

But $Node = menu_get_object() is not retuning node object.

The scenario

//nodes Items of custom content type.
Title : Sony LCD
Tags : electronic

Title : The godfather
Tags :Books
.
.
Items(n)

//node of custom content type Review. It's node id is 10
Title : Make a Review
Filter Tags : Taxonomy terms reference (e.x electronic, books, movies etc)

//attach a entityform to above node using entity reference and also back referenced with enityreference_current
My Review Item : EnityReference field - Entity reference view - Autocomplete widget
Review : text area

When node/10 is viewed, user will have to fill "my review item",but should be filter based on "Filter tags" that was already set.

code on view's php code under contextual filter

$node = menu_get_object ();
$ Related_ids = array ();
    $ Related = field_get_items ('node', $node, 'field_filter_tags') // Get the term reference field
    if ($related && is_array ($related) && sizeof ($related)> 0) {
      for ($i = 0; $i <count ($related); $i++) {
        $ Related_ids [] = $related [$i]['target_id'];
      }
    }
    return implode (',', $related_ids);//to perform AND 

Comments

MustangGB’s picture

Status: Active » Closed (outdated)

Closing this as outdated, feel free to re-open with updated details if it's still a problem in the latest release.