You are here

public function AuthorPaneBlock::build in Author Pane 8.3

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/AuthorPaneBlock.php, line 75
Contains \Drupal\author_pane\Plugin\Block\AuthorPane.

Class

AuthorPaneBlock
Provides a Author Pane block.

Namespace

Drupal\author_pane\Plugin\Block

Code

public function build() {
  $block = array();

  // Try to determine the author from context.
  $author = $this
    ->findAuthor();

  // If we have no author, we can't build the pane.
  if (!is_null($author)) {
    $config = $this
      ->getConfiguration();
    $this->authorPane = $this->authorPaneManager
      ->load($config['author_pane']);
    $this->authorPane
      ->setAuthor($author);
    $content = $this->authorPane
      ->display();

    // @TODO: More advanced theming on the block?
    $block = array(
      '#markup' => $content,
    );
  }
  return $block;
}