7 – Drupal countries programmatically receive continent of ISO2

To continue the answer to the first question, I think you need to load the country entity to replace the token with the values ​​you are looking for.

Countries are stored as a custom unit based on the Country module:

/ **
* Implements hook_entity_info ().
* /
Function countries_entity_info () {
$ return = array (
& # 39; country & # 39; => array (
& # 39; label & # 39; => t (& # 39; land & # 39;),
"Plural name" => t ("countries"),
& Lt; entity class & # 39; => & # 39; entity & # 39 ;,
& # 39; controller class & # 39; => & # 39; EntityAPIControllerExportable & # 39 ;,
& # 39; base table & # 39; => & # 39; countries_country & # 39 ;,
& # 39; token type & # 39; => & # 39; country & # 39 ;,
& # 39; # 39 & capable field; => TRUE,
"Module" => "countries",
& # 39; # 39 & object key; => Array (
& # 39; id & # 39; => & Cir & # 39 ;,
& # 39; name & # 39; => & # 39; iso2 & # 39 ;,
& # 39; label & # 39; => & # 39; name & # 39 ;,
)
& # 39; bundles & # 39; => Array (
& # 39; country & # 39; => array (
& # 39; label & # 39; => t (& # 39; land & # 39;),
& # 39; admin & # 39; => Array (
"Path" => "Admin / Config / Regional / Countries",
& # 39; access arguments & # 39; => manage array (& # 39; site configuration & # 39 ;,)
)
)
)
& # 39; # 39 & viewing modes; => Array (
& # 39; full & # 39; => array (
& # 39; label & # 39; => t (& # 39; land & # 39;),
& # 39; custom settings & # 39; => FALSE,
)
)
)
);
return $ return;
}

/ **
* Loads a country unit according to ISO Alpha 2 code.
*
* This is also a placeholder for menus.
*
* @param string $ iso2
* An ISO alpha 2 string. This does not differentiate between uppercase and lowercase.
*
* @return object
* A country object loaded by the entity controller.
* /
Function country_load ($ iso2) {
// The URL should be case-insensitive.
$ iso2 = $ iso2? drupal_strtoupper ($ iso2): $ iso2;
return entity_load_single (& # 39; country & # 39 ;, $ iso2);
}

It looks as iso2 value is the Entity ID based on this code and Helper Load Helper. So you can access the whole entity if a token is replaced by:

/ **
* Implemented hook_tokens ().
* /
Function MYMODULE_tokens ($ type, $ tokens, array $ data = array (), array $ options = array ()) {
$ Substitutions = [];

if ($ type == & nbsp; & nbsp; & nbsp; &&! void ($ data['node']) && array_key_exists (& # 39; MYTOKEN & # 39;, $ tokens)) {
$ country = country_load ($ data)['node']-> field_prgm_country[LANGUAGE_NONE][0]['iso2']);
// $ country should be a fully loaded country unit with all fields and properties
// check out $ country here with ksm ($ country); exit;
$ replacement['[node:MYTOKEN]& # 39]= // data you want to display;
}

return replacement;
}

It looks like the Country module offers its own Country: of tokens, but I do not know how (or if) they work in the context of fields on a node. This should at least come closer to you.