1818use RedberryProducts \PageBuilderPlugin \Components \Forms \Actions \EditPageBuilderBlockAction ;
1919use RedberryProducts \PageBuilderPlugin \Components \Forms \Actions \ReoraderPageBuilderBlockAction ;
2020use RedberryProducts \PageBuilderPlugin \Components \Forms \Actions \SelectBlockAction ;
21+ use RedberryProducts \PageBuilderPlugin \Traits \ComponentLoadsPageBuilderBlocks ;
2122
22- // TODO: make this reorder-able
2323class PageBuilder extends Field
2424{
25- public ? string $ relationship = null ;
25+ use ComponentLoadsPageBuilderBlocks ;
2626
2727 public bool | Closure $ reorderable = false ;
2828
@@ -42,7 +42,6 @@ class PageBuilder extends Field
4242
4343 protected ?Closure $ renderReorderActionButtonUsing = null ;
4444
45- public array | Closure $ blocks = [];
4645
4746 public string $ view = 'page-builder-plugin::forms.page-builder ' ;
4847
@@ -293,14 +292,6 @@ public function reorderAction(
293292 return $ this ;
294293 }
295294
296- public function blocks (
297- array | Closure $ blocks ,
298- ) {
299- $ this ->blocks = $ blocks ;
300-
301- return $ this ;
302- }
303-
304295 public function reorderable (
305296 bool | Closure $ reorderable = true ,
306297 ) {
@@ -314,18 +305,6 @@ public function getReorderable(): bool
314305 return (bool ) $ this ->evaluate ($ this ->reorderable );
315306 }
316307
317- #[Computed(true )]
318- public function getBlocks (): array
319- {
320- $ evaluated = $ this ->evaluate ($ this ->blocks );
321-
322- if (is_array ($ evaluated )) {
323- return $ evaluated ;
324- }
325-
326- return [];
327- }
328-
329308 public function getBlockSchema (string $ blockType , ?Model $ record , Component $ component , Page $ livewire ): array
330309 {
331310 return $ blockType ::getBlockSchema (
@@ -389,11 +368,12 @@ public function relationship(
389368 }
390369
391370 public function renderPreviewWithIframes (
392- bool | Closure $ value ,
371+ bool | Closure $ condition = true ,
393372 string | Closure $ createUrl ,
373+ // TODO: make one of them optional
394374 string | Closure $ updateUrl ,
395375 ) {
396- $ value = (bool ) $ this ->evaluate ($ value );
376+ $ condition = (bool ) $ this ->evaluate ($ condition );
397377
398378 $ this ->createAction (function (CreatePageBuilderBlockAction $ action ) use ($ createUrl ) {
399379 return $ action ->pageBuilderPreviewField (function (PageBuilderPreview $ field ) use ($ createUrl ) {
@@ -409,10 +389,4 @@ public function renderPreviewWithIframes(
409389
410390 return $ this ;
411391 }
412-
413- public function getConstrainAppliedQuery (Model $ record )
414- {
415- return $ record ->{$ this ->relationship }()
416- ->whereIn ('block_type ' , $ this ->getBlocks ());
417- }
418392}
0 commit comments