1 layout_renderer_standard.inc LayoutRendererStandard::renderBlock($block)

Render a block using its designated style.

This method also manages 'title block' functionality, where the title from an individual block can be bubbled up to take over the title for the entire display.

Parameters

Block $block: The block to be rendered.

Return value

string: The rendered block as HTML.

File

core/modules/layout/plugins/renderers/layout_renderer_standard.inc, line 498

Class

LayoutRendererStandard
The standard render for a Layout display object.

Code

function renderBlock($block) {
  // Pass any page title to the page components block before rendering it.
  if (method_exists($block, 'setPageTitle')) {
    /* @var $block PageComponents */
    $page_title = isset($this->page_title) ? $this->page_title : backdrop_get_title();
    $block->setPageTitle($page_title);
  }

  $output = '';
  if ($content = $block->getContent()) {
    $style = layout_get_style_info($block->style->plugin);

    // Ensure block content is a renderable array for contextual links.
    if (is_string($content)) {
      $content = array(
        '#markup' => $content,
      );
    }
    // Add the contextual links.
    if (!($block->module === 'system' && $block->delta === 'main')) {
      $content['#contextual_links']['layout'] = array('admin/structure/layouts/manage/' . $this->layout->name . '/modal', array($block->uuid));
    }

    $title = '';
    if ($block->settings['title_display'] !== LAYOUT_TITLE_NONE) {
      $title = $block->getTitle();
    }

    $data = array(
      'title' => $title,
      'content' => $content,
    );

    // Allow altering of the title and content by other modules.
    backdrop_alter(array('block_view', 'block_view_' . $block->module . '_' . str_replace('-', '_', $block->delta)), $data, $block);

    // Assemble a structured content array.
    $content = (object) array(
      'title' => $data['title'],
      'content' => $data['content'],
    );

    if (isset($style) && isset($style['block theme'])) {
      $output = theme($style['block theme'] . '__' . $block->module . '__' . strtr($block->delta, '-', '_'), array('content' => $content, 'layout' => $this->layout, 'block' => $block, 'style' => $style, 'settings' => $block->style->settings));
    }
    else {
      // Fallback.
      $output = theme('block', array('content' => $content, 'layout' => $this->layout, 'block' => $block));
    }
  }
  return $output;
}