first import
This commit is contained in:
70
sites/all/modules/ctools/plugins/arguments/entity_id.inc
Normal file
70
sites/all/modules/ctools/plugins/arguments/entity_id.inc
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for all entity ids
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Entity: ID"),
|
||||
'description' => t('Creates an entity context from an entity ID argument.'),
|
||||
'context' => 'ctools_argument_entity_id_context',
|
||||
'get child' => 'ctools_argument_entity_id_get_child',
|
||||
'get children' => 'ctools_argument_entity_id_get_children',
|
||||
);
|
||||
|
||||
function ctools_argument_entity_id_get_child($plugin, $parent, $child) {
|
||||
$plugins = ctools_argument_entity_id_get_children($plugin, $parent);
|
||||
return $plugins[$parent . ':' . $child];
|
||||
}
|
||||
|
||||
function ctools_argument_entity_id_get_children($original_plugin, $parent) {
|
||||
$entities = entity_get_info();
|
||||
$plugins = array();
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
$plugin = $original_plugin;
|
||||
$plugin['title'] = t('@entity: ID', array('@entity' => $entity['label']));
|
||||
$plugin['keyword'] = $entity_type;
|
||||
$plugin['description'] = t('Creates @entity context from an ID argument.', array('@entity' => $entity_type));
|
||||
$plugin['name'] = $parent . ':' . $entity_type;
|
||||
$plugin_id = $parent . ':' . $entity_type;
|
||||
drupal_alter('ctools_entity_context', $plugin, $entity, $plugin_id);
|
||||
$plugins[$plugin_id] = $plugin;
|
||||
}
|
||||
drupal_alter('ctools_entity_contexts', $plugins);
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the entity we crave.
|
||||
*/
|
||||
function ctools_argument_entity_id_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
$entity_type = explode(':', $conf['name']);
|
||||
$entity_type = $entity_type[1];
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:' . $entity_type);
|
||||
}
|
||||
|
||||
// We can accept either an entity object or a pure id.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('entity:' . $entity_type, $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$entity = entity_load($entity_type, array($arg));
|
||||
if (!$entity) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('entity:' . $entity_type, $entity[$arg]);
|
||||
}
|
||||
|
50
sites/all/modules/ctools/plugins/arguments/nid.inc
Normal file
50
sites/all/modules/ctools/plugins/arguments/nid.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a node id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node: ID"),
|
||||
'keyword' => 'node',
|
||||
'description' => t('Creates a node context from a node ID argument.'),
|
||||
'context' => 'ctools_argument_nid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the node ID of a node for this argument'),
|
||||
),
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$node = node_load($arg);
|
||||
if (!$node) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('node', $node);
|
||||
}
|
||||
|
32
sites/all/modules/ctools/plugins/arguments/node_add.inc
Normal file
32
sites/all/modules/ctools/plugins/arguments/node_add.inc
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Node add form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node add form: node type"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'node_type',
|
||||
'description' => t('Creates a node add form context from a node type argument.'),
|
||||
'context' => 'ctools_node_add_context',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_node_add_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if (!isset($arg)) {
|
||||
return ctools_context_create_empty('node_add_form');
|
||||
}
|
||||
|
||||
return ctools_context_create('node_add_form', $arg);
|
||||
}
|
||||
|
51
sites/all/modules/ctools/plugins/arguments/node_edit.inc
Normal file
51
sites/all/modules/ctools/plugins/arguments/node_edit.inc
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Node edit form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node edit form: node ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'node',
|
||||
'description' => t('Creates a node edit form context from a node ID argument.'),
|
||||
'context' => 'ctools_node_edit_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the node ID of a node for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_node_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node_edit_form');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node_edit_form', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$node = node_load($arg);
|
||||
if (!$node) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This will perform a node_access check, so we don't have to.
|
||||
return ctools_context_create('node_edit_form', $node);
|
||||
}
|
||||
|
50
sites/all/modules/ctools/plugins/arguments/rid.inc
Normal file
50
sites/all/modules/ctools/plugins/arguments/rid.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a node revision id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Revision: ID"),
|
||||
'keyword' => 'revision',
|
||||
'description' => t('Creates a node context from a revision ID argument.'),
|
||||
'context' => 'ctools_argument_rid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the revision ID of a node for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_argument_rid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$nid = db_query('SELECT nid FROM {node_revisions} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
|
||||
$node = node_load($nid, $arg);
|
||||
if (!$node) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('node', $node);
|
||||
}
|
||||
|
64
sites/all/modules/ctools/plugins/arguments/string.inc
Normal file
64
sites/all/modules/ctools/plugins/arguments/string.inc
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a raw string
|
||||
*/
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("String"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'string',
|
||||
'description' => t('A string is a minimal context that simply holds a string that can be used for some other purpose.'),
|
||||
'settings form' => 'ctools_string_settings_form',
|
||||
'context' => 'ctools_string_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a value for this argument'),
|
||||
),
|
||||
'path placeholder' => 'ctools_string_path_placeholder', // This is in pagemanager.
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_string_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('string');
|
||||
}
|
||||
|
||||
$context = ctools_context_create('string', $arg);
|
||||
$context->original_argument = $arg;
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_string_settings_form(&$form, &$form_state, $conf) {
|
||||
$form['settings']['use_tail'] = array(
|
||||
'#title' => t('Get all arguments after this one'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['use_tail']),
|
||||
'#description' => t('If checked, this string will include all arguments. For example, if the path is "path/%" and the user visits "path/foo/bar", if this is not checked the string will be "foo". If it is checked the string will be "foo/bar".'),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch the placeholder based upon user settings.
|
||||
*/
|
||||
function ctools_string_path_placeholder($argument) {
|
||||
if (empty($argument['settings']['use_tail'])) {
|
||||
return '%pm_arg';
|
||||
}
|
||||
else {
|
||||
return '%pm_arg_tail';
|
||||
}
|
||||
}
|
163
sites/all/modules/ctools/plugins/arguments/term.inc
Normal file
163
sites/all/modules/ctools/plugins/arguments/term.inc
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy term: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'term',
|
||||
'description' => t('Creates a single taxonomy term from a taxonomy ID or taxonomy term name.'),
|
||||
'context' => 'ctools_term_context',
|
||||
'default' => array('input_form' => 'tid', 'breadcrumb' => TRUE, 'transform' => FALSE),
|
||||
'settings form' => 'ctools_term_settings_form',
|
||||
'placeholder form' => 'ctools_term_ctools_argument_placeholder',
|
||||
'breadcrumb' => 'ctools_term_breadcrumb',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:taxonomy_term');
|
||||
}
|
||||
|
||||
if (is_object($arg)) {
|
||||
$term = $arg;
|
||||
}
|
||||
else {
|
||||
switch ($conf['input_form']) {
|
||||
case 'tid':
|
||||
default:
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
$term = taxonomy_term_load($arg);
|
||||
break;
|
||||
|
||||
case 'term':
|
||||
if (!empty($conf['transform'])) {
|
||||
$arg = strtr($arg, '-', ' ');
|
||||
}
|
||||
|
||||
$terms = taxonomy_get_term_by_name($arg);
|
||||
|
||||
$conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL;
|
||||
if ((count($terms) > 1) && isset($conf['vids'])) {
|
||||
foreach ($terms as $potential) {
|
||||
foreach ($conf['vids'] as $vid => $active) {
|
||||
if ($active && $potential->vid == $vid) {
|
||||
$term = $potential;
|
||||
// break out of the foreaches AND the case
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$term = array_shift($terms);
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($term)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$context = ctools_context_create('entity:taxonomy_term', $term);
|
||||
$context->original_argument = $arg;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_term_settings_form(&$form, &$form_state, $conf) {
|
||||
// @todo allow synonym use like Views does.
|
||||
$form['settings']['input_form'] = array(
|
||||
'#title' => t('Argument type'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array('tid' => t('Term ID'), 'term' => t('Term name')),
|
||||
'#default_value' => $conf['input_form'],
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
$options = array();
|
||||
foreach ($vocabularies as $vid => $vocab) {
|
||||
$options[$vid] = $vocab->name;
|
||||
}
|
||||
$form['settings']['vids'] = array(
|
||||
'#title' => t('Limit to these vocabularies'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#default_value' => !empty($conf['vids']) ? $conf['vids'] : array(),
|
||||
'#description' => t('If no vocabularies are checked, terms from all vocabularies will be accepted.'),
|
||||
);
|
||||
|
||||
$form['settings']['breadcrumb'] = array(
|
||||
'#title' => t('Inject hierarchy into breadcrumb trail'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['breadcrumb']),
|
||||
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
|
||||
);
|
||||
|
||||
$form['settings']['transform'] = array(
|
||||
'#title' => t('Transform dashes in URL to spaces in term name filter values'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['transform']),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form fragment to get an argument to convert a placeholder for preview.
|
||||
*/
|
||||
function ctools_term_ctools_argument_placeholder($conf) {
|
||||
switch ($conf['input_form']) {
|
||||
case 'tid':
|
||||
default:
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a taxonomy term ID.'),
|
||||
);
|
||||
case 'term':
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a taxonomy term name.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the breadcrumb trail if necessary.
|
||||
*/
|
||||
function ctools_term_breadcrumb($conf, $context) {
|
||||
if (empty($conf['breadcrumb']) || empty($context->data) || empty($context->data->tid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$breadcrumb = array();
|
||||
$current = new stdClass();
|
||||
$current->tid = $context->data->tid;
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
||||
}
|
||||
|
||||
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
}
|
77
sites/all/modules/ctools/plugins/arguments/terms.inc
Normal file
77
sites/all/modules/ctools/plugins/arguments/terms.inc
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy term (multiple): ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'term',
|
||||
'description' => t('Creates a group of taxonomy terms from a list of tids separated by a comma or a plus sign. In general the first term of the list will be used for panes.'),
|
||||
'context' => 'ctools_terms_context',
|
||||
'default' => array('breadcrumb' => TRUE),
|
||||
'settings form' => 'ctools_terms_settings_form',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a term ID or a list of term IDs separated by a + or a ,'),
|
||||
),
|
||||
'breadcrumb' => 'ctools_terms_breadcrumb',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_terms_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('terms');
|
||||
}
|
||||
|
||||
$terms = ctools_break_phrase($arg);
|
||||
if (empty($terms->value) || !empty($terms->invalid_input)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$context = ctools_context_create('terms', $terms);
|
||||
$context->original_argument = $arg;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_terms_settings_form(&$form, &$form_state, $conf) {
|
||||
$form['settings']['breadcrumb'] = array(
|
||||
'#title' => t('Inject hierarchy of first term into breadcrumb trail'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['breadcrumb']),
|
||||
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the breadcrumb trail if necessary.
|
||||
*/
|
||||
function ctools_terms_breadcrumb($conf, $context) {
|
||||
if (empty($conf['breadcrumb'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current->tid = $context->tids[0];
|
||||
$breadcrumb = array();
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
||||
}
|
||||
|
||||
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
}
|
53
sites/all/modules/ctools/plugins/arguments/uid.inc
Normal file
53
sites/all/modules/ctools/plugins/arguments/uid.inc
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a user id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user context from a user ID argument.'),
|
||||
'context' => 'ctools_argument_uid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the user ID of a user for this argument'),
|
||||
),
|
||||
'default' => array('to_arg' => TRUE),
|
||||
'path placeholder' => '%pm_uid_arg', // This is in pagemanager.
|
||||
'path placeholder to_arg' => TRUE,
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the user we crave.
|
||||
*/
|
||||
function ctools_argument_uid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('user', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$account = user_load($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctools_context_create('user', $account);
|
||||
}
|
48
sites/all/modules/ctools/plugins/arguments/user_edit.inc
Normal file
48
sites/all/modules/ctools/plugins/arguments/user_edit.inc
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User edit form: User ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user edit form context from a user ID argument.'),
|
||||
'context' => 'ctools_user_edit_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the user ID for this argument.'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_user_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user_edit_form');
|
||||
}
|
||||
if(is_object($arg)){
|
||||
return ctools_context_create('user_edit_form', $arg);
|
||||
}
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$account= user_load($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This will perform a node_access check, so we don't have to.
|
||||
return ctools_context_create('user_edit_form', $account);
|
||||
return NULL;
|
||||
}
|
47
sites/all/modules/ctools/plugins/arguments/user_name.inc
Normal file
47
sites/all/modules/ctools/plugins/arguments/user_name.inc
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a username
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: name"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user context from a user name.'),
|
||||
'context' => 'ctools_argument_user_name_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the username of a user for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the user we crave.
|
||||
*/
|
||||
function ctools_argument_user_name_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('user', $arg);
|
||||
}
|
||||
|
||||
$account = user_load_by_name($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
return ctools_context_create('user', $account);
|
||||
}
|
||||
|
||||
|
||||
|
46
sites/all/modules/ctools/plugins/arguments/vid.inc
Normal file
46
sites/all/modules/ctools/plugins/arguments/vid.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a vocabulary id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Vocabulary: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'vocabulary',
|
||||
'description' => t('Creates a vocabulary context from a vocabulary ID argument.'),
|
||||
'context' => 'ctools_vid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the vocabulary ID for this argument'),
|
||||
),
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the vocabulary we crave.
|
||||
*/
|
||||
function ctools_vid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:taxonomy_vocabulary');
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$vocabulary = taxonomy_vocabulary_load($arg);
|
||||
if (!$vocabulary) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctools_context_create('vocabulary', $vocabulary);
|
||||
}
|
||||
|
Reference in New Issue
Block a user