You are here

public function RecentGroupContentBlock::build in Organic groups 8

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/RecentGroupContentBlock.php, line 182

Class

RecentGroupContentBlock
Provides a block that shows recent group content for the current group.

Namespace

Drupal\og\Plugin\Block

Code

public function build() {

  // Do not render anything if there is no group in the current context.
  if (empty($this->ogContext
    ->getGroup())) {
    return [];
  }
  $list = array_map(function ($entity) {
    return [
      '#type' => 'link',
      '#title' => $entity
        ->label(),
      '#url' => $entity
        ->toUrl(),
    ];
  }, $this
    ->getGroupContent());
  return [
    'list' => [
      '#theme' => 'item_list',
      '#items' => $list,
    ],
  ];
}