Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍💻 Add textdomain to blocks (Fixes #233) #234

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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