summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2011-09-07 22:44:49 (GMT)
committer Earl Miles2011-09-07 22:44:49 (GMT)
commitb55f958ca846248c5fa989f9bf1f2fd726fa3e02 (patch)
tree06d406efd9838ac83bb1e3f1ea244b10e3316ded
parent0fe9eb673c16aae8646de7404a25cb000bd70159 (diff)
Issue #1241170: ctools_context_get_defaults() badly non-functional, needed some redo.
-rw-r--r--includes/context-admin.inc22
1 files changed, 18 insertions, 4 deletions
diff --git a/includes/context-admin.inc b/includes/context-admin.inc
index bda61e3..464b3e6 100644
--- a/includes/context-admin.inc
+++ b/includes/context-admin.inc
@@ -345,7 +345,7 @@ function ctools_context_ajax_item_add($mechanism = NULL, $type = NULL, $cache_ke
// Set up the $conf array for this plugin
if (empty($step) || empty($object->temporary)) {
// Create the basis for our new context.
- $conf = ctools_context_get_defaults($plugin_definition);
+ $conf = ctools_context_get_defaults($plugin_definition, $object, $type);
$object->temporary = &$conf;
}
else {
@@ -614,7 +614,22 @@ function ctools_context_ajax_item_edit($mechanism = NULL, $type = NULL, $cache_k
exit;
}
-function ctools_context_get_defaults($plugin_definition) {
+/**
+ * Get the defaults for a new instance of a context plugin.
+ *
+ * @param $plugin_definition
+ * The metadata definition of the plugin from ctools_get_plugins().
+ * @param $object
+ * The object the context plugin will be added to.
+ * @param $type
+ * The type of context plugin. i.e, context, requiredcontext, relationship
+ */
+function ctools_context_get_defaults($plugin_definition, $object, $type) {
+ // Fetch the potential id of the plugin so we can append
+ // title and keyword information for new ones.
+ $type_info = ctools_context_info($type);
+ $id = ctools_context_next_id($object->{$type_info['key']}, $plugin_definition['name']);
+
$conf = array(
'identifier' => $plugin_definition['title'] . ($id > 1 ? ' ' . $id : ''),
'keyword' => ctools_get_keyword($object, $plugin_definition['keyword']),
@@ -652,7 +667,6 @@ function ctools_edit_context_form_defaults($form, &$form_state) {
$object = $form_state['object'];
$plugin_definition = $form_state['plugin'];
$type_info = $form_state['type info'];
- $position = $form_state['position'];
$contexts = $form_state['contexts'];
$conf = $form_state['conf'];
@@ -796,7 +810,7 @@ function ctools_get_keyword($page, $word) {
}
$keyword = $word;
- $count = 0;
+ $count = 1;
while (!empty($keywords[$keyword])) {
$keyword = $word . '_' . ++$count;
}