From 35afac709de3d9838f6a02f62db66e7a95073693 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 14 Mar 2024 08:48:21 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20`text?= =?UTF-8?q?domain`=20to=20blocks=20(Fixes=20#233)=20(#234)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Block.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Block.php b/src/Block.php index 925deb1b..00244b28 100644 --- a/src/Block.php +++ b/src/Block.php @@ -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. * @@ -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. */ @@ -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, @@ -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,