|
6 | 6 | use Illuminate\Support\Arr; |
7 | 7 | use Illuminate\Support\Collection; |
8 | 8 | use Illuminate\Support\Str; |
9 | | -use Log1x\AcfComposer\Concerns\FormatsCss; |
10 | 9 | use Log1x\AcfComposer\Concerns\InteractsWithBlade; |
11 | 10 | use Log1x\AcfComposer\Contracts\Block as BlockContract; |
| 11 | +use WP_Block_Supports; |
12 | 12 |
|
13 | 13 | use function Roots\asset; |
14 | 14 |
|
15 | 15 | abstract class Block extends Composer implements BlockContract |
16 | 16 | { |
17 | | - use FormatsCss, InteractsWithBlade; |
| 17 | + use InteractsWithBlade; |
18 | 18 |
|
19 | 19 | /** |
20 | 20 | * The block properties. |
@@ -416,70 +416,36 @@ public function getSupportAttributes(): array |
416 | 416 | return $attributes; |
417 | 417 | } |
418 | 418 |
|
| 419 | + /** |
| 420 | + * Retrieve the block HTML attributes. |
| 421 | + */ |
| 422 | + public function getSupportHtmlAttributes(): array |
| 423 | + { |
| 424 | + return once(fn () => WP_Block_Supports::get_instance()->apply_block_supports()); |
| 425 | + } |
| 426 | + |
419 | 427 | /** |
420 | 428 | * Retrieve the inline block styles. |
421 | 429 | */ |
422 | 430 | public function getInlineStyle(): string |
423 | 431 | { |
424 | | - return $this->collect([ |
425 | | - 'padding' => ! empty($this->block->style['spacing']['padding']) |
426 | | - ? $this->collect($this->block->style['spacing']['padding']) |
427 | | - ->map(fn ($value, $side) => $this->formatCss($value, $side)) |
428 | | - ->implode(' ') |
429 | | - : null, |
430 | | - |
431 | | - 'margin' => ! empty($this->block->style['spacing']['margin']) |
432 | | - ? $this->collect($this->block->style['spacing']['margin']) |
433 | | - ->map(fn ($value, $side) => $this->formatCss($value, $side, 'margin')) |
434 | | - ->implode(' ') |
435 | | - : null, |
436 | | - |
437 | | - 'color' => ! empty($this->block->style['color']['gradient']) |
438 | | - ? sprintf('background: %s;', $this->block->style['color']['gradient']) |
439 | | - : null, |
440 | | - ])->filter()->implode(' '); |
| 432 | + $supports = $this->getSupportHtmlAttributes(); |
| 433 | + |
| 434 | + return $supports['style'] ?? ''; |
441 | 435 | } |
442 | 436 |
|
443 | 437 | /** |
444 | 438 | * Retrieve the block classes. |
445 | 439 | */ |
446 | 440 | public function getClasses(): string |
447 | 441 | { |
448 | | - $classes = $this->collect([ |
449 | | - 'slug' => Str::of($this->slug)->slug()->start('wp-block-')->toString(), |
450 | | - |
451 | | - 'className' => $this->block->className ?? null, |
452 | | - |
453 | | - 'align' => ! empty($this->block->align) |
454 | | - ? Str::start($this->block->align, 'align') |
455 | | - : null, |
456 | | - |
457 | | - 'backgroundColor' => ! empty($this->block->backgroundColor) |
458 | | - ? sprintf('has-background has-%s-background-color', $this->block->backgroundColor) |
459 | | - : null, |
460 | | - |
461 | | - 'textColor' => ! empty($this->block->textColor) |
462 | | - ? sprintf('has-%s-color', $this->block->textColor) |
463 | | - : null, |
| 442 | + $supports = $this->getSupportHtmlAttributes(); |
464 | 443 |
|
465 | | - 'gradient' => ! empty($this->block->gradient) |
466 | | - ? sprintf('has-%s-gradient-background', $this->block->gradient) |
467 | | - : null, |
468 | | - ]); |
469 | | - |
470 | | - if ($alignText = $this->block->alignText ?? $this->block->align_text ?? null) { |
471 | | - $classes->add(Str::start($alignText, 'align-text-')); |
472 | | - } |
473 | | - |
474 | | - if ($alignContent = $this->block->alignContent ?? $this->block->align_content ?? null) { |
475 | | - $classes->add(Str::start($alignContent, 'is-position-')); |
476 | | - } |
477 | | - |
478 | | - if ($this->block->fullHeight ?? $this->block->full_height ?? null) { |
479 | | - $classes->add('full-height'); |
480 | | - } |
481 | | - |
482 | | - return $classes->filter()->implode(' '); |
| 444 | + return str_replace( |
| 445 | + acf_slugify($this->namespace), |
| 446 | + $this->slug, |
| 447 | + $supports['class'] ?? '' |
| 448 | + ); |
483 | 449 | } |
484 | 450 |
|
485 | 451 | /** |
|
0 commit comments