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 @@ '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 @@ } } } + +/** + * 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 6c2f9b7..2f9c18a 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -1353,6 +1353,48 @@ ), ); + 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'), @@ -1471,6 +1513,12 @@ $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..63bd694 100644 --- a/plugins/content_types/fieldable_panels_pane.inc +++ b/plugins/content_types/fieldable_panels_pane.inc @@ -191,6 +191,25 @@ } } + // 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); + } + return $block; } }