You are here

public function GroupAddBookBlock::build in Open Social 8.9

Same name and namespace in other branches
  1. 8.3 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  2. 8.4 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  3. 8.5 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  4. 8.6 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  5. 8.7 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  6. 8.8 modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  7. 10.3.x modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  8. 10.0.x modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  9. 10.1.x modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::build()
  10. 10.2.x modules/social_features/social_book/src/Plugin/Block/GroupAddBookBlock.php \Drupal\social_book\Plugin\Block\GroupAddBookBlock::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_book/src/Plugin/Block/GroupAddBookBlock.php, line 60

Class

GroupAddBookBlock
Provides a 'GroupAddBookBlock' block.

Namespace

Drupal\social_book\Plugin\Block

Code

public function build() {
  $build = [];
  if (\Drupal::moduleHandler()
    ->moduleExists('social_group')) {
    $group = _social_group_get_current_group();
  }
  else {
    $group = NULL;
  }
  if (is_object($group)) {
    $url = Url::fromUserInput("/group/{$group->id()}/content/create/group_node:book");
    $link_options = [
      'attributes' => [
        'class' => [
          'btn',
          'btn-primary',
          'btn-raised',
          'waves-effect',
          'brand-bg-primary',
        ],
      ],
    ];
    $url
      ->setOptions($link_options);
    $build['content'] = Link::fromTextAndUrl(t('Create book page'), $url)
      ->toRenderable();

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