Created
May 24, 2017 19:00
-
-
Save walidvb/e14aaabb194e01d11c9774dcad27f573 to your computer and use it in GitHub Desktop.
Fetching a node context from url alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_module_ctools_plugin_directory($module, $plugin) { | |
if ($module == 'ctools' && !empty($plugin)) { | |
return "plugins/$plugin"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in plugins/arguments/ | |
<?php | |
$plugin = array( | |
'title' => t("Concert: Title"), | |
'description' => t('Creates a node context from a concert title argument.'), | |
'context' => 'gc_custom_argument_node_title_context', | |
'placeholder form' => array( | |
'#type' => 'textfield', | |
'#description' => t('Enter the node title of a node for this argument'), | |
), | |
); | |
function gc_custom_argument_node_title_context($arg = NULL, $conf = NULL, $empty = FALSE) { | |
// watchdog('ctools', | |
// 'I am running. arg: ' . $arg, | |
// WATCHDOG_NOTICE); // uncomment and watch wd for debug | |
if ($empty) { | |
return ctools_context_create_empty('node'); | |
} // not sure ... | |
if (is_object($arg)) { | |
return ctools_context_create('node', $arg); | |
} // ...if these two are really necessary. Do we ever get an object? | |
// pain, as this requires to have the full node alias, rather than just the node title "hyphenated" | |
$alias = "concert/$arg"; | |
$path = drupal_lookup_path("source", $alias); | |
$node = menu_get_object("node", 1, $path); | |
if (!$node) { | |
return FALSE; | |
} | |
return ctools_context_create('node', $node); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment