diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install index 9bfc67d..d5c011b 100644 --- a/fieldable_panels_panes.install +++ b/fieldable_panels_panes.install @@ -31,6 +31,13 @@ function fieldable_panels_panes_uninstall() { // Variables. variable_del('fieldable_panels_panes_skip_default_type'); + variable_del('fpp_blocks_expose'); + + // Delete any variables that begin with 'fpp_expose_' + $results = db_query('SELECT name FROM {variable} WHERE name LIKE :var', array(':var'=> 'fpp_expose_%'))->fetchCol(); + foreach ($results as $var) { + variable_del($var); + } } /** diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module index 0437e1f..566176e 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -406,6 +406,14 @@ function fieldable_panels_panes_menu() { 'type' => MENU_LOCAL_ACTION, ) + $base; + // Settings + $items['admin/structure/fieldable-panels-panes/settings'] = array( + 'title' => 'Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('fieldable_panels_panes_settings'), + 'type' => MENU_LOCAL_TASK, + ) + $base; + return $items; } @@ -735,6 +743,79 @@ function fieldable_panels_panes_views_api() { } // ------------------------------------------------------------------------- +// Block hooks + +/** + * Implements hook_block_info(). + */ +function fieldable_panels_panes_block_info() { + $blocks = array(); + // Get array of exposed FPP bundles + $bundles = fieldable_panels_panes_exposed_bundles(); + + if (variable_get('fpp_blocks_expose', FALSE) == TRUE) { + // Get all reusable entities if $bundles array is empty + if (empty($bundles)) { + $ids = db_query('SELECT fpid FROM {fieldable_panels_panes} WHERE reusable = 1')->fetchCol(); + } + // Get reusable entities of selected FPP bundles if $bundles array is not empty + else { + $ids = array(); + foreach ($bundles as $bundle => $info) { + $bundle_ids = db_query('SELECT fpid FROM {fieldable_panels_panes} WHERE reusable = 1 AND bundle = :bundle', array(':bundle' => $bundle))->fetchCol(); + $ids = array_merge($ids, $bundle_ids); + } + } + $entities = fieldable_panels_panes_load_multiple($ids); + foreach ($entities as $entity) { + $blocks[$entity->fpid]['info'] = 'FPP (' . $entity->bundle . '): ' . entity_label('fieldable_panels_pane', $entity); + } + } + return $blocks; +} + +/** + * Implements hook_block_view(). + */ +function fieldable_panels_panes_block_view($delta = '') { + $block = array(); + // Get array of exposed FPP bundles + $bundles = fieldable_panels_panes_exposed_bundles(); + + if (variable_get('fpp_blocks_expose', FALSE) == TRUE) { + $entity = fieldable_panels_panes_load($delta); + $bundle = $entity->bundle; + + $block['subject'] = ''; + $block['content'] = ''; + + // Render block if its FPP bundle is exposed and block is reusable + if ((array_key_exists($bundle, $bundles) || empty($bundles)) && $entity->reusable == TRUE) { + $content = fieldable_panels_panes_view($entity); + $block['subject'] = check_plain($entity->title); + $block['content'] = $content; + } + } + return $block; +} + +/** + * Return array of FPP bundles exposed as blocks + */ +function fieldable_panels_panes_exposed_bundles() { + // Get array of all FPP bundles and unset bundles not exposed as blocks + $bundles = fieldable_panels_panes_get_bundle_labels(); + + foreach ($bundles as $bundle => $info) { + $expose = variable_get('fpp_expose_'.$bundle, FALSE); + if ($expose == FALSE) { + unset($bundles[$bundle]); + } + } + return $bundles; +} + +// ------------------------------------------------------------------------- // Theming /** diff --git a/includes/admin.inc b/includes/admin.inc index fa62511..3680dc5 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -6,6 +6,55 @@ */ /** + * Page callback for settings page. + */ + +function fieldable_panels_panes_settings() { + // Get array of all FPP bundles + $bundles = fieldable_panels_panes_get_bundle_labels(); + + $form = array(); + $form['fpp_blocks_expose'] = array( + '#type' => 'checkbox', + '#title' => t('Make fieldable panels panes available as blocks'), + '#description' => t('Fieldable panels panes that are resuable will be made available as blocks.'), + '#default_value' => variable_get('fpp_blocks_expose', FALSE), + ); + $form['bundles'] = array( + '#type' => 'fieldset', + '#title' => t('FPP Types Exposed as Blocks'), + '#description' => t('Select FPP types to be exposed as blocks. If none is selected, then all FPP types will be exposed as blocks.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="fpp_blocks_expose"]' => array('checked' => TRUE), + ), + ), + ); + + // Render checkbox for each FPP bundle if any FPP bundles exist + if (!empty($bundles)) { + foreach ($bundles as $bundle => $info) { + $form['bundles']['fpp_expose_'.$bundle] = array( + '#type' => 'checkbox', + '#title' => t($info), + '#default_value' => variable_get('fpp_expose_'.$bundle, FALSE), + ); + } + } + + // Remove fieldset description and add markup if no FPP bundles exist + else { + $form['bundles']['empty'] = array( + '#markup' => t('

No FPP types exist.

'), + ); + $form['bundles']['#description'] = NULL; + } + return system_settings_form($form); +} + +/** * List all entities for the given type. */ function fieldable_panels_panes_entities_list_page($type) {