Skip to content
Snippets Groups Projects
Commit a7729b13 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3322771 by smustgrave: QuickTabs...

Issue #3322771 by smustgrave: QuickTabs Drupal\Component\Plugin\Exception\ContextException: The 'entity:node' context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 73 of core/lib/Drupal/Core/Plugin/Context/Context.php)
parent f4b1f963
No related branches found
No related tags found
1 merge request!14Issue #3189439: Last clicked tab history should be configurable
Pipeline #533527 passed
......@@ -2,12 +2,18 @@
namespace Drupal\quicktabs\Plugin\TabType;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Drupal\Core\Session\AccountProxyInterface;
......@@ -25,6 +31,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class BlockContent extends TabTypeBase implements ContainerFactoryPluginInterface {
use MessengerTrait;
/**
* {@inheritDoc}
*/
......@@ -100,14 +108,17 @@ class BlockContent extends TabTypeBase implements ContainerFactoryPluginInterfac
*/
public function render(array $tab) {
$options = $tab['content'][$tab['type']]['options'];
$render = [];
try {
if (str_contains($options['bid'], 'block_content')) {
$parts = explode(':', $options['bid']);
$block = $this->entityRepository->loadEntityByUuid($parts[0], $parts[1]);
$block_content = $this->entityTypeManager->getStorage('block_content')->load($block->id());
$render = $this->entityTypeManager->getViewBuilder('block_content')->view($block_content);
$block_content = $this->entityTypeManager->getStorage('block_content')
->load($block->id());
$render = $this->entityTypeManager->getViewBuilder('block_content')
->view($block_content);
}
else {
// You can hard code configuration, or you load from settings.
$config = [];
......@@ -119,9 +130,13 @@ class BlockContent extends TabTypeBase implements ContainerFactoryPluginInterfac
if ($access_result->isForbidden()) {
return [];
}
$render = $plugin_block->build();
}
}
catch (ContextException | InvalidPluginDefinitionException | PluginNotFoundException | EntityStorageException | PluginException$e) {
$this->messenger()->addError($this->t('Unable to render block content with @id. @error',
['@id' => $options['bid'], '@error' => $e->getMessage()]));
}
return $render;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment