Problem/Motivation
After enabling ui_patterns_block submodule and using components as block on layout builder, I've got the following error:
Undefined array key "bundle" in Drupal\ui_patterns_blocks\Plugin\Block\ComponentBlock->getComponentSourceContexts() (line 137 of modules/contrib/ui_patterns/modules/ui_patterns_blocks/src/Plugin/Block/ComponentBlock.php).
Proposed resolution
On modules/ui_patterns_blocks/src/Plugin/Block/ComponentBlock.php block plugin line 137
replace: if (!$this->context["bundle"] && isset($this->context["entity"]))
by: if (!isset($this->context["bundle"]) && isset($this->context["entity"]))
Issue fork ui_patterns-3471587
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
b.khouyComment #4
b.khouyComment #5
pdureau commentedHi Brahim,
Source: https://www.php.net/manual/fr/function.isset.php
Are we losing something with this change? What is happening if
$this->context["bundle"]return a value resolving tofalse, but not tonull?Those are genuine questions, not rhetorical, I am not a PHP expert.
Comment #6
pdureau commentedComment #7
pdureau commentedalready done in #3467502: [2.0.0-beta2] ContextHelper cleaning
But we will not forget you in the credits
Comment #8
b.khouy@pdureau
If
$this->context["bundle"]is expected to return either astring(the bundle), aboolean(for reasons that are unclear), ornull, and the condition needs to be valid when the bundle is not null or when the bundle is false, the condition should be written like this:if (!isset($this->context["bundle"]) && $this->context["bundle"] && isset($this->context["entity"])) {Ultimately, the correct approach depends on your requirements. You're right I see that it has already been resolved in: #3467502: [2.0.0-beta2] ContextHelper cleaning
:)