From ef530ccdb24453d3ac10df4c54e7a5d978fc1b51 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Tue, 10 Jun 2025 09:39:54 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A8=20refactor:=20extract=20compon?= =?UTF-8?q?entAttributeBag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Block.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Block.php b/src/Block.php index 44ed5a3..f4ad7f2 100644 --- a/src/Block.php +++ b/src/Block.php @@ -501,6 +501,17 @@ public function getClasses(): string ); } + /** + * Retrieve the component attribute bag. + */ + protected function getComponentAttributeBag(): ComponentAttributeBag + { + return (new ComponentAttributeBag) + ->class($this->getClasses()) + ->style($this->getInlineStyle()) + ->filter(fn ($value) => filled($value) && $value !== ';'); + } + /** * Retrieve the block API version. */ @@ -778,11 +789,6 @@ public function render($block, $content = '', $preview = false, $post_id = 0, $w $this->style = $this->getStyle(); $this->inlineStyle = $this->getInlineStyle(); - $attributes = (new ComponentAttributeBag) - ->class($this->classes) - ->style($this->inlineStyle) - ->filter(fn ($value) => filled($value) && $value !== ';'); - if (! is_admin() && method_exists($this, 'assets')) { $instance = (array) ($this->block ?? []); @@ -793,7 +799,7 @@ public function render($block, $content = '', $preview = false, $post_id = 0, $w return $this->view($this->view, [ 'block' => $this, - 'attributes' => $attributes, + 'attributes' => $this->getComponentAttributeBag(), ]); } From 750875bb61cd3c30cdb690c8a26c8babbbb66549 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Tue, 10 Jun 2025 09:42:13 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20block=20anchor=20?= =?UTF-8?q?to=20attribute=20bag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Block.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Block.php b/src/Block.php index f4ad7f2..c82f58b 100644 --- a/src/Block.php +++ b/src/Block.php @@ -509,6 +509,7 @@ protected function getComponentAttributeBag(): ComponentAttributeBag return (new ComponentAttributeBag) ->class($this->getClasses()) ->style($this->getInlineStyle()) + ->merge(['id' => $this->block->anchor ?? null]) ->filter(fn ($value) => filled($value) && $value !== ';'); }