Skip to content

Commit

Permalink
Allow blockContext without template (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Mar 7, 2022
1 parent 9d936a6 commit 8e79c65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/Block/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ final class BlockContext implements BlockContextInterface
*/
public function __construct(BlockInterface $block, array $settings = [])
{
if (!\array_key_exists('template', $settings)) {
@trigger_error(
'Not providing a "template" setting is deprecated since sonata-project/block-bundle 4.10'
.' and will be throw an exception in version 5.0.',
\E_USER_DEPRECATED
);

// NEXT_MAJOR: Uncomment the exception instead.
// throw new \InvalidArgumentException('The "template" setting is required.');
} elseif (!\is_string($settings['template'])) {
@trigger_error(
'Not providing a string value for the "template" setting is deprecated since'
.' sonata-project/block-bundle 4.10 and will be throw an exception in version 5.0.',
\E_USER_DEPRECATED
);

// NEXT_MAJOR: Uncomment the exception instead.
// throw new \InvalidArgumentException('The "template" setting MUST be a string.');
}

$this->block = $block;
$this->settings = $settings;
}
Expand Down Expand Up @@ -91,6 +71,19 @@ public function setSetting(string $name, $value): BlockContextInterface
*/
public function getTemplate(): ?string
{
return $this->getSetting('template');
$template = $this->getSetting('template');

if (!\is_string($template)) {
@trigger_error(
'Not providing a string value for the "template" setting is deprecated since'
.' sonata-project/block-bundle 4.10 and will be throw an exception in version 5.0.',
\E_USER_DEPRECATED
);

// NEXT_MAJOR: Uncomment the exception instead.
// throw new \InvalidArgumentException('The "template" setting MUST be a string.');
}

return $template;
}
}
1 change: 1 addition & 0 deletions src/Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function get($meta, array $settings = []): BlockContextInterface
$e->getMessage()
));

// NEXT_MAJOR: Only pass the template value if it's a string.
$settings = $this->resolve($block, $settings + ['template' => $block->getSetting('template')]);
}

Expand Down

0 comments on commit 8e79c65

Please sign in to comment.