@@ -501,6 +501,18 @@ public function getClasses(): string
501501 );
502502 }
503503
504+ /**
505+ * Retrieve the component attribute bag.
506+ */
507+ protected function getComponentAttributeBag (): ComponentAttributeBag
508+ {
509+ return (new ComponentAttributeBag )
510+ ->class ($ this ->getClasses ())
511+ ->style ($ this ->getInlineStyle ())
512+ ->merge (['id ' => $ this ->block ->anchor ?? null ])
513+ ->filter (fn ($ value ) => filled ($ value ) && $ value !== '; ' );
514+ }
515+
504516 /**
505517 * Retrieve the block API version.
506518 */
@@ -778,11 +790,6 @@ public function render($block, $content = '', $preview = false, $post_id = 0, $w
778790 $ this ->style = $ this ->getStyle ();
779791 $ this ->inlineStyle = $ this ->getInlineStyle ();
780792
781- $ attributes = (new ComponentAttributeBag )
782- ->class ($ this ->classes )
783- ->style ($ this ->inlineStyle )
784- ->filter (fn ($ value ) => filled ($ value ) && $ value !== '; ' );
785-
786793 if (! is_admin () && method_exists ($ this , 'assets ' )) {
787794 $ instance = (array ) ($ this ->block ?? []);
788795
@@ -793,7 +800,7 @@ public function render($block, $content = '', $preview = false, $post_id = 0, $w
793800
794801 return $ this ->view ($ this ->view , [
795802 'block ' => $ this ,
796- 'attributes ' => $ attributes ,
803+ 'attributes ' => $ this -> getComponentAttributeBag () ,
797804 ]);
798805 }
799806
0 commit comments