How to create a link to edit a specific field value of a node inside views using views php?

801 views Asked by At

I am using views php by adding a custom php code field to my view display, so I have the $data variable available. Inside the custom php code, I am rendering fields that have been added with a field collection relationship:

<?php
global $user;
$html = array();

if (count($data->field_field_poi_link) > 0) $html[] = 'foobar';

if ($user->uid != 0 && arg(0) == 'node' && node_access('update', 'foobar', $user)) {
  $nid = arg(1);
  // $html[] = '<a class="inl_edit" href="'.$data->_entity_properties['url'].'/edit?destination=node/'.$nid.'">edit</a>';
  // $html[] = '<a class="inl_del" href="'.$data->_entity_properties['url'].'/delete?destination=node/'.$nid.'">delete</a>';
}
print join("\n",$html);

?>

Before the entity api update on 10th Jan the $data->_entity_properties array contained this:

'_entity_properties' => 
  array (
    'url' => 'http://localhost:8888/project/field-collection/field-poi-link/39',
  ),

but now, it contains nothing like that. I cant edit that one specific entry.

How can I create a link to edit one specific value for each field collection's entered field data like http://localhost:8888/project/field-collection/field-pois/74/edit inside a views php field?

1

There are 1 answers

0
Hossein Jazayeri On

Maybe it's better if you use views hooks; That's more safer than views_php. As an example you could see hook_views_pre_execute