Skip to content

Commit 852c688

Browse files
committed
Handle Empty Content & Be More Robust
1 parent f5875b6 commit 852c688

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Plugin/AddCmsBlockIdentifierToMarkup.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ public function beforeSave(
3636
BlockRepositoryInterface $subject,
3737
BlockInterface $block
3838
): array {
39-
if ($this->moduleConfig->isBlockIdentifierMarkupEnabled() && $block->getIdentifier()) {
39+
if ($this->moduleConfig->isBlockIdentifierMarkupEnabled()
40+
&& ($identifier = $block->getIdentifier())
41+
&& ($content = $block->getContent())
42+
) {
4043
$block->setContent(
4144
substr_replace(
42-
$block->getContent(),
43-
" data-{$this->moduleConfig->getBlockIdentifierDataAttributeName()}=\"{$block->getIdentifier()}\"",
44-
strpos($block->getContent(), ' '),
45+
$content,
46+
' data-' . $this->moduleConfig->getBlockIdentifierDataAttributeName() . '="' . $identifier . '"',
47+
strpos($content, '<div') + 4,
4548
0
4649
)
4750
);

0 commit comments

Comments
 (0)