You are here

public function GroupHeroBlock::build in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  2. 8 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  3. 8.2 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  4. 8.3 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  5. 8.4 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  6. 8.5 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  7. 8.6 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  8. 8.8 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  9. 10.3.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  10. 10.0.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  11. 10.1.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()
  12. 10.2.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php \Drupal\social_group\Plugin\Block\GroupHeroBlock::build()

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

modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php, line 64

Class

GroupHeroBlock
Provides a 'GroupHeroBlock' block.

Namespace

Drupal\social_group\Plugin\Block

Code

public function build() {
  $build = [];
  $group = _social_group_get_current_group();
  if (!empty($group)) {

    // Content.
    $content = \Drupal::entityTypeManager()
      ->getViewBuilder('group')
      ->view($group, 'hero');
    $build['content'] = $content;

    // Cache tags.
    $build['#cache']['tags'][] = 'group_block:' . $group
      ->id();
  }

  // Cache contexts.
  $build['#cache']['contexts'][] = 'url.path';
  return $build;
}