country_code.inc in Countries 8
Same filename and directory in other branches
Plugin to provide an argument handler for a country entity.
File
plugins/arguments/country_code.incView source
<?php
/**
* @file
* Plugin to provide an argument handler for a country entity.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t("Country: ISO Code"),
// keyword to use for %substitution
'keyword' => 'country',
'description' => t('Creates a country context from a ISO code argument. Accepts alpha-2, alpha-3 and numeric codes.'),
'context' => 'countries_country_code_context',
'placeholder form' => array(
'#type' => 'textfield',
'#description' => t('Enter the country ISO code for this argument.'),
),
);
/**
* Discover if this argument gives us the term we crave.
*/
function countries_country_code_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// If unset it wants a generic, unfilled context.
if ($empty) {
return ctools_context_create_empty('entity:country');
}
// We can accept either a country entity or a pure nid.
if (is_object($arg)) {
return ctools_context_create('entity:country', $arg);
}
// A very generic country lookup is done here.
// This will fallback to names, etc, but only ISO codes are really safe.
if ($country = countries_country_lookup($arg)) {
return ctools_context_create('entity:country', $country);
}
return FALSE;
}
Functions
Name | Description |
---|---|
countries_country_code_context | Discover if this argument gives us the term we crave. |