Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Provide Drupal blocks as content.
- *
- * Since blocks don't provide all of the features we do, we have to do a little
- * extra work, including providing icons and categories for core blocks. Blocks
- * from contrib modules get to provide their own stuff, or get relegated to
- * the old "Miscellaneous" category.
- */
- /**
- * Plugins are described by creating a $plugin array which will be used
- * by the system that includes this file.
- */
- $plugin = array(
- // And this is just the administrative title.
- // All our callbacks are named according to the standard pattern and can be deduced.
- 'title' => t('Facet Block'),
- 'content type' => 'solr_shows_facet_blocks_content_type_content_type',
- 'render last' => TRUE,
- );
- /**
- * Return the block content types with the specified $subtype_id.
- */
- function solr_shows_facet_blocks_content_type_content_type($subtype_id) {
- list($module, $delta) = explode('-', $subtype_id, 2);
- $module_blocks = module_invoke('facetapi', 'block_info');
- if (isset($module_blocks[$delta])) {
- return _solr_shows_facet_blocks_content_type_content_type($module, $delta, $module_blocks[$delta]);
- }
- }
- /**
- * Return all block content types available.
- *
- * Modules wanting to make special adjustments the way that CTools handles their blocks
- * can implement an extension to the hook_block() family, where the function name is
- * of the form "$module . '_solr_shows_facet_blocks_info'".
- */
- function solr_shows_facet_blocks_content_type_content_types() {
- $types = array();
- $module = 'facetapi';
- $module_blocks = module_invoke($module, 'block_info');
- if ($module_blocks) {
- foreach ($module_blocks as $delta => $block) {
- $info = _solr_shows_facet_blocks_content_type_content_type($module, $delta, $block);
- // this check means modules can remove their blocks; particularly useful
- // if they offer the block some other way (like we do for views)
- if ($info) {
- $types["facet_blocks-$delta"] = $info;
- }
- }
- }
- return $types;
- }
- /**
- * Return an info array for a specific block.
- */
- function _solr_shows_facet_blocks_content_type_content_type($module, $delta, $block) {
- // strip_tags used because it goes through check_plain and that
- // just looks bad.
- $info = array(
- 'title' => strip_tags($block['info']),
- );
- // Ask around for further information by invoking the hook_block() extension.
- $function = $module . '_solr_shows_facet_blocks_info';
- if (!function_exists($function)) {
- $function = 'solr_shows_default_block_info';
- }
- $function($module, $delta, $info);
- return $info;
- }
- /**
- * Output function for the 'block' content type. Outputs a block
- * based on the module and delta supplied in the configuration.
- */
- function solr_shows_facet_blocks_content_type_render($subtype, $conf) {
- list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
- $module = 'facetapi';
- $info = new stdClass;
- $info->module = $module;
- $info->delta = $delta;
- $block = module_invoke($module, 'block_view', $delta);
- // Allow modules to modify the block before it is viewed, via either
- // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
- drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);
- $block = (object) $block;
- if (empty($block)) {
- return;
- }
- $block->module = $module;
- $block->delta = $delta;
- if (isset($block->subject)) {
- $block->title = $block->subject;
- }
- else {
- $block->title = NULL;
- }
- if (module_exists('block') && user_access('administer blocks')) {
- $block->admin_links = array(
- array(
- 'title' => t('Configure block'),
- 'href' => "admin/structure/block/manage/$module/$delta/configure",
- 'query' => drupal_get_destination(),
- ),
- );
- }
- return $block;
- }
- /**
- * Empty form so we can have the default override title.
- */
- function solr_shows_facet_blocks_content_type_edit_form($form, &$form_state) {
- // Does nothing!
- return $form;
- }
- /**
- * Submit function to fix the subtype for really old panel panes.
- */
- function solr_shows_facet_blocks_content_type_edit_form_submit($form, &$form_state) {
- if (empty($form_state['subtype']) && isset($form_state['pane'])) {
- $form_state['pane']->subtype = $form_state['conf']['module'] . '-' . $form_state['conf']['delta'];
- unset($form_state['conf']['module']);
- unset($form_state['conf']['delta']);
- }
- }
- /**
- * Returns the administrative title for a type.
- */
- function solr_shows_facet_blocks_content_type_admin_title($subtype, $conf) {
- list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
- $module = 'facetapi';
- $block = module_invoke($module, 'block_info');
- if (empty($block) || empty($block[$delta])) {
- return t('Deleted/missing block @module-@delta', array('@module' => $module, '@delta' => $delta));
- }
- // The block description reported by hook_block() is plain text, but the title
- // reported by this hook should be HTML.
- $title = check_plain($block[$delta]['info']);
- return $title;
- }
- /**
- * Output function for the 'block' content type. Outputs a block
- * based on the module and delta supplied in the configuration.
- */
- function solr_shows_facet_blocks_content_type_admin_info($subtype, $conf) {
- list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
- $module = 'facetapi';
- $block = (object) module_invoke($module, 'block', 'view', $delta);
- // Sanitize the block because <script> tags can hose javascript up:
- if (!empty($block->content)) {
- $block->content = filter_xss_admin($block->content);
- }
- if (!empty($block) && !empty($block->subject)) {
- $block->title = $block->subject;
- return $block;
- }
- }
- function _solr_shows_facet_blocks_get_module_delta($subtype, $conf) {
- if (strpos($subtype, '-')) {
- return explode('-', $subtype, 2);
- }
- else {
- return array($conf['module'], $conf['delta']);
- }
- }
- /**
- * Provide default icon and categories for blocks when modules don't do this
- * for us.
- */
- function solr_shows_default_block_info($module, $delta, &$info) {
- $info['icon'] = 'icon_contrib_block.png';
- $info['category'] = t('Facets');
- }
Advertisement
Add Comment
Please, Sign In to add comment