I want to create a new token form the selected item in the list box of currently submited node and set it as url alias of the node.
unfortunately, I need keys of select box as token but default tokens do not have this item(it just has labels of listboxes). so I decided to create it's token programmatically.
this is the code but I do not know how to set selected item of list box in $value
function cool_token_token_info() {
$info['tokens']['node']['key1'] = array(
'name' => t('My cool token'),
'description' => t('A token I use to show that I am cool.'),
);
return $info;
}
function cool_token_tokens($type, $tokens, array $data = array(), array $options = array(),$node=array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type == 'node') {
// Loop through the available tokens.
foreach ($tokens as $name => $original) {
// Find our custom tokens by name.
switch ($name) {
case 'key1':
// Work out the value of our token.
if (isset($node)){
$value= "here I want to have key of the selected item in the listbox of current node";
}else{
$value="not working";
}
// Give our token it's value!
$replacements[$original] = $value;
break;
}
}
}
return $replacements;
}
I tried
field_get_items('node', $node, 'field_parent')
and many many other ways but it does not print anything