I want to use Views Datasource module to output JSON, i then want to construct the JSON output using REACT JS or alike. I am currently stuck on how to output the Flag Link, it just comes back with an OPS field. Ideally i want this as a plain link so I can trigger it through jquery/ajax.

Views Field

Ops Field

UPDATE: as requested using the php field i managed to get the output i was after which is something like: plain text output

  • I might have a possible alternative for you to consider. But can you first enhance your question to better explain what I should see (or not see) in the JSON sample in your (last) picture. Maybe something like "this is what I get, but this is what I would like to get"? Feb 4 '16 at 6:38
  • @Pierre.Vriens done Feb 4 '16 at 10:28
  • OK, that helps already quite a bit to better understand. But is your new result now something like the first JSON picture, in which the lines in your last picture are inserted somewhere? And also: did you actually "manage" to do so using Views PHP (as in your answer)? Last question: do you insist in using "Views datasource" (and views PHP), or are you open to an alternative solution that does not require those 2 modules? Just to make sure my possible answer might fit "also", ok? Feb 4 '16 at 10:59
  • @Pierre.Vriens, my new result is in the right format i.e. showing me the path to the flag and with token. yes i did manage to do it with Views PHP and no i don;t insist on using View data source and Views PHP (would much rather avoid using Views PHP), but Viewsdata source makes it very easy. Feb 6 '16 at 0:06

Unfortunately I couldn't get the perfect solution to this so I had to use Views PHP. Remember to add a hidden field for the nid of the node

$link = flag_create_link('MyFlagMachineName', $row->nid);
preg_match_all('/<a[^>]+href=([\'"])(.+?)\1[^>]*>/i', $link, $result);
if (!empty($result)) {
  echo $result[2][0];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.