diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install
index 7fb9c54..ad38292 100644
--- a/fieldable_panels_panes.install
+++ b/fieldable_panels_panes.install
@@ -84,6 +84,11 @@ function fieldable_panels_panes_schema() {
'type' => 'varchar',
'length' => 255,
),
+ 'substitute' => array(
+ 'description' => 'Whether or not to perform keyword substitutions.',
+ 'type' => 'int',
+ 'size' => 'tiny',
+ ),
'reusable' => array(
'description' => 'Whether or not this entity will appear in the Add Content dialog.',
'type' => 'int',
@@ -717,3 +722,16 @@ function fieldable_panels_panes_update_7114() {
}
}
}
+
+/**
+ * Add context keyword substitution support.
+ */
+function fieldable_panels_panes_update_7115() {
+ if (!db_field_exists('fieldable_panels_panes', 'substitute')) {
+ db_add_field('fieldable_panels_panes', 'substitute', array(
+ 'description' => 'Whether or not to perform keyword substitutions.',
+ 'type' => 'int',
+ 'size' => 'tiny',
+ ));
+ }
+}
diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module
index d3e0b0d..2bdaaa3 100644
--- a/fieldable_panels_panes.module
+++ b/fieldable_panels_panes.module
@@ -1351,6 +1351,48 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) {
),
);
+ if (!empty($form_state['contexts'])) {
+ // Set extended description if both Field and Token modules are enabled,
+ // notifying of unlisted keywords
+ if (module_exists('field') && module_exists('token')) {
+ $description = t('If checked, context keywords will be substituted in this content. Note that custom fields may be used as keywords using patterns like %node:field_name-formatted.');
+ }
+ elseif (!module_exists('token')) {
+ $description = t(
+ 'If checked, context keywords will be substituted in this content. More keywords will be available if the Token module is installed.',
+ array('@token-url' => 'http://drupal.org/project/token')
+ );
+ }
+ else {
+ $description = t('If checked, context keywords will be substituted in this content.');
+ }
+
+ $form['substitute'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use context keywords'),
+ '#description' => $description,
+ '#default_value' => !empty($entity->substitute),
+ );
+ $form['contexts'] = array(
+ '#title' => t('Substitutions'),
+ '#type' => 'fieldset',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ $rows = array();
+ foreach ($form_state['contexts'] as $context) {
+ foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
+ $rows[] = array(
+ check_plain($keyword),
+ t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
+ );
+ }
+ }
+ $header = array(t('Keyword'), t('Value'));
+ $form['contexts']['context'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $rows)));
+ }
+
$form['admin']['admin_title'] = array(
'#type' => 'textfield',
'#title' => t('Administrative title'),
@@ -1469,6 +1511,12 @@ function fieldable_panels_panes_entity_edit_form_submit($form, &$form_state) {
$entity->log = $form_state['values']['log'];
}
+ // The substitute field is only added when an FPP is added when contexts exist
+ // (eg: in the Panels UI).
+ if (isset($form_state['values']['substitute'])) {
+ $entity->substitute = $form_state['values']['substitute'];
+ }
+
field_attach_submit('fieldable_panels_pane', $entity, $form, $form_state);
fieldable_panels_panes_save($entity);
diff --git a/plugins/content_types/fieldable_panels_pane.inc b/plugins/content_types/fieldable_panels_pane.inc
index ee10fd6..c6ecc0c 100644
--- a/plugins/content_types/fieldable_panels_pane.inc
+++ b/plugins/content_types/fieldable_panels_pane.inc
@@ -191,6 +191,29 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_render($subty
}
}
+ // Handle keyword substitutions for both title and content.
+ if (!empty($entity->substitute)) {
+ foreach (element_children($block->content) as $child) {
+ if (!empty($block->content[$child]['#items'])) {
+ foreach ($block->content[$child]['#items'] as $index => $info) {
+ if (!empty($block->content[$child][$index]['#markup'])) {
+ $block->content[$child][$index]['#markup'] = ctools_context_keyword_substitute($block->content[$child][$index]['#markup'], array(), $context);
+ }
+ }
+ }
+ elseif (!empty($block->content[$child]['#value'])) {
+ $block->content[$child]['#value'] = ctools_context_keyword_substitute($block->content[$child]['#value'], array(), $context);
+ }
+ }
+ }
+ if (!empty($block->title)) {
+ $block->title = ctools_context_keyword_substitute($block->title, array(), $context);
+ }
+
+ if (!empty($entity->path)) {
+ $entity->path = ctools_context_keyword_substitute($entity->path, array(), $context);
+ }
+
return $block;
}
}