Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Add textdomain to blocks (Fixes #233) (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Mar 14, 2024
1 parent e501cfe commit 35afac7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ abstract class Block extends Composer implements BlockContract
*/
public $prefix = 'acf/';

/**
* The block text domain.
*
* @var string
*/
public $textDomain;

/**
* The block namespace.
*
Expand Down Expand Up @@ -383,6 +390,16 @@ public function getClasses(): string
return $classes->filter()->implode(' ');
}

/**
* Retrieve the block text domain.
*/
public function getTextDomain(): string
{
return $this->textDomain
?? wp_get_theme()?->get('TextDomain')
?? 'acf-composer';
}

/**
* Handle the block template.
*/
Expand Down Expand Up @@ -465,6 +482,7 @@ public function settings(): Collection
'styles' => $this->getStyles(),
'supports' => $this->supports,
'enqueue_assets' => fn ($block) => method_exists($this, 'assets') ? $this->assets($block) : null,
'textdomain' => $this->getTextDomain(),
'acf_block_version' => 2,
'render_callback' => function (
$block,
Expand Down Expand Up @@ -508,9 +526,10 @@ public function settings(): Collection
public function toJson(): string
{
$settings = $this->settings()->forget([
'acf_block_version',
'enqueue_assets',
'render_callback',
'mode',
'render_callback',
])->put('acf', [
'mode' => $this->mode,
'renderTemplate' => $this::class,
Expand Down

0 comments on commit 35afac7

Please sign in to comment.