You are here

public function BlockContent::render in Quick Tabs 8.3

Return a render array for an individual tab tat the theme layer to process.

Return value

string @todo test if changing type to array works

Overrides TabTypeBase::render

File

src/Plugin/TabType/BlockContent.php, line 62

Class

BlockContent
Provides a 'block content' tab type.

Namespace

Drupal\quicktabs\Plugin\TabType

Code

public function render(array $tab) {
  $options = $tab['content'][$tab['type']]['options'];
  if (strpos($options['bid'], 'block_content') !== FALSE) {
    $parts = explode(':', $options['bid']);
    $entity_repository = \Drupal::service('entity.repository');
    $block = $entity_repository
      ->loadEntityByUuid($parts[0], $parts[1]);
    $entityTypeManager = \Drupal::entityTypeManager();
    $block_content = $entityTypeManager
      ->getStorage('block_content')
      ->load($block
      ->id());
    $render = $entityTypeManager
      ->getViewBuilder('block_content')
      ->view($block_content);
  }
  else {
    $block_manager = \Drupal::service('plugin.manager.block');

    // You can hard code configuration or you load from settings.
    $config = [];
    $plugin_block = $block_manager
      ->createInstance($options['bid'], $config);

    // Some blocks might implement access check.
    $access_result = $plugin_block
      ->access(\Drupal::currentUser(), TRUE);

    // Return empty render array if user doesn't have access.
    if ($access_result
      ->isForbidden()) {
      return [];
    }
    $render = $plugin_block
      ->build();
  }
  return $render;
}