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

Issue #3293922 by shobhit91, smustgrave: Call to a member function getRenderArray() on null

parent 9d280ab1
No related branches found
No related tags found
3 merge requests!21Issue #3407343 Add theme template for loading animation/markup,!14Issue #3189439: Last clicked tab history should be configurable,!11Issue #3238148: Tabs still displayed even when empty
Pipeline #430150 canceled
......@@ -2,30 +2,25 @@
namespace Drupal\quicktabs\Plugin\Block;
use Drupal\block_content\Plugin\Derivative\BlockContent;
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a 'QuickTabs' block.
*
* @Block(
* id = "quicktabs_block",
* admin_label = @Translation("QuickTabs Block"),
* category = @Translation("QuickTabs"),
* deriver = "Drupal\quicktabs\Plugin\Derivative\QuickTabsBlock"
* )
*/
#[Block(
id: "quicktabs_block",
admin_label: new TranslatableMarkup("QuickTabs Block"),
category: new TranslatableMarkup("QuickTabs"),
deriver: \Drupal\quicktabs\Plugin\Derivative\QuickTabsBlock::class
)]
class QuickTabsBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a BlockComponentRenderArray object.
*
......@@ -35,18 +30,17 @@ class QuickTabsBlock extends BlockBase implements ContainerFactoryPluginInterfac
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager'));
}
......@@ -57,6 +51,14 @@ class QuickTabsBlock extends BlockBase implements ContainerFactoryPluginInterfac
$qt_id = $this->getDerivativeId();
$qt = $this->entityTypeManager->getStorage('quicktabs_instance')->load($qt_id);
if (!isset($qt)) {
return [
'#markup' => $this->t('Broken QuickTabs block with ID: @id', [
'@id' => $this->getDerivativeId(),
]),
];
}
return $qt->getRenderArray();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment