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 inside VIEWS PHP 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
Update : I also tried with $node= node_load(arg(1));
, this time $node variable set but not type of node. Then I dpm(arg(1));
it shows string autocomplete(yes just autocomplete not string entered in field).
menu_get_object
gets a loaded object from a router item. If you call it when non-node is displayed, it simply cannot return node. Where exactly do you call it? And what exactly does it return?dpr($node);
in your code and tell us what really is there, OK?Notice: Undefined variable: node in eval() (line 8 of C:\server\www\mysite.local\sites\all\modules\views\plugins\views_plugin_argument_default_php.inc(53) : eval()'d code)
.Another thing menu_get_object() is called without parameter as default is 'node'.Is it possible to use entity_metada_wrapper inside view's php code section to get node?dpr(menu_get_object())
also fails, we have a problem. What you say about entity_metada_wrapper sounds reasonable, but I can't tell now, sorry.