I recall being able to use $node->title; in the 6.x branch, but it doesn't seem to work using 7.x. Here's the code I'm trying to use:

$player = $node->title;

/* gets the data from a URL */
function get_data($url)
{
	$ch = curl_init();
	$timeout = 5;
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
}

$entity_field[0]['value'] = get_data('http://someurl.com/'.$player.'.txt');

Any ideas?

Comments

JHuxley’s picture

Can you use the nid to get the title? If so this worked for me:

<?php
$mynid = $entity->nid;
?>

The entity variable is an array with a lot of useful stuff. Can't remember if the title is in there directly, actually.

adrinux’s picture

Just hit the same issue. I can't see how to examine the content of $entity, so I ended up just doing node_load() after your suggesting of $entity->nid

$mynid = $entity->nid;
$node = node_load($mynid);
$fullname = $node->title;
preg_match('~([^\s]+)(?:,.*)?$~', $fullname, $match);
$entity_field[0]['value'] = $match[0];

The rest happens to extract the last word of the title, in my case a surname :)

blasthaus’s picture

doesn't $entity->title work?

stephen verdant’s picture

blasthaus, I think you're right, $entity->title works for me.

Here's two ways to explore $entity:

print '<pre>';
print "Entity title is " . $entity->title . "\n";

print_r($entity); // [1] ugly splatter
krumo($entity); // [2] turn devel module on first!

The node_load approach is useful for more complex efforts, like getting the title of a node that this node references.

colan’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.