diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install index 3c54648..83c13ba 100644 --- a/fieldable_panels_panes.install +++ b/fieldable_panels_panes.install @@ -36,6 +36,11 @@ function fieldable_panels_panes_schema() { 'type' => 'varchar', 'length' => 255, ), + 'block' => array( + 'description' => 'Whether or not this entity will render as a block.', + 'type' => 'int', + 'size' => 'tiny', + ), 'link' => array( 'description' => 'Whether or not this entity title will link to another page.', 'type' => 'int', @@ -233,3 +238,10 @@ function fieldable_panels_panes_update_7106() { )); } } + +/** + * Add support to render panes as blocks. + */ +function fieldable_panels_panes_update_7107() { + db_add_field('fieldable_panels_panes', 'block', array('type' => 'int', 'size' => 'tiny', 'description' => 'Whether or not this entity will render as a block.')); +} diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module index 2ee4513..a50c8bd 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -607,6 +607,54 @@ function fieldable_panels_panes_views_api() { } // ------------------------------------------------------------------------- +// Block hooks + +/** + * Get a list of fieldable panel panes. + * + * @return + * An array of FPP entities that are set to be rendered as blocks. + */ +function fieldable_panels_pane_get_blockable_entities() { + $fpid_result = db_select('fieldable_panels_panes', 'f') + ->fields('f', array('fpid')) + ->condition('block', 1, '=') + ->execute(); + + $fpids = array(); + foreach ($fpid_result as $fpid) { + $fpids[] = $fpid->fpid; + } + + $entities = fieldable_panels_panes_load_multiple($fpids); + return $entities; +} + +/** + * Implements hook_block_info(). + */ +function fieldable_panels_panes_block_info() { + $blocks = array(); + + $entities = fieldable_panels_pane_get_blockable_entities(); + foreach ($entities as $entity) { + $blocks[$entity->fpid]['info'] = entity_label('fieldable_panels_pane', $entity); + } + return $blocks; +} + +/** + * Implements hook_block_view(). + */ +function fieldable_panels_panes_block_view($delta = '') { + $entity = entity_load_single('fieldable_panels_pane', $delta); + $content = entity_view('fieldable_panels_pane', array($entity)); + $block['subject'] = check_plain($entity->title); + $block['content'] = $content; + return $block; +} + +// ------------------------------------------------------------------------- // Theming /** @@ -889,6 +937,13 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { $form['revision']['#access'] = FALSE; } + $form['block'] = array( + '#type' => 'checkbox', + '#title' => t('Render this entity as a block'), + '#default_value' => $entity->block, + '#weight' => 9, + ); + $form['reusable']['reusable'] = array( '#type' => 'checkbox', '#title' => t('Make this entity reusable'), @@ -979,6 +1034,7 @@ function fieldable_panels_panes_entity_edit_form_submit($form, &$form_state) { $entity->link = $form_state['values']['link']; $entity->path = $form_state['values']['path']; $entity->language = $form_state['values']['language']; + $entity->block = $form_state['values']['block']; $entity->reusable = $form_state['values']['reusable']; $entity->category = $form_state['values']['category']; $entity->admin_title = $form_state['values']['admin_title']; diff --git a/includes/PanelsPaneController.class.php b/includes/PanelsPaneController.class.php index 6692a8f..c8b1b6a 100644 --- a/includes/PanelsPaneController.class.php +++ b/includes/PanelsPaneController.class.php @@ -279,6 +279,7 @@ class PanelsPaneController extends DrupalDefaultEntityController { $values += array( 'bundle' => 'fieldable_panels_pane', 'title' => '', + 'block' => FALSE, 'link' => '', 'path' => '', 'reusable' => FALSE,