From be7b7f4c13c229d73c9d4ad866b691b5e4d1d355 Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Tue, 23 Sep 2025 13:34:24 +0200 Subject: [PATCH 1/2] refactor: getting getID module method for blocks --- source/php/Module.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/php/Module.php b/source/php/Module.php index 1b4fe8956..768dff800 100644 --- a/source/php/Module.php +++ b/source/php/Module.php @@ -326,6 +326,21 @@ public function collectViewData() $this->data = array_merge($this->data, $this->data()); } + /** + * Get the ID of the module or block + * @return int|string|null + */ + protected function getID(): int|string|null + { + if ($this->ID) { + $id = $this->ID; + } else { + $id = acf_get_valid_post_id( false ); + } + + return $id ?: null; + } + /** * Get metadata for block or module. * @return array From 857f2fe37dab2579eaaec83a5b66d8359ffdb1e3 Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Tue, 23 Sep 2025 13:43:19 +0200 Subject: [PATCH 2/2] refactor: getFields --- source/php/Module.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/php/Module.php b/source/php/Module.php index 768dff800..67b04dac3 100644 --- a/source/php/Module.php +++ b/source/php/Module.php @@ -18,7 +18,7 @@ class Module * A place to store the id of a module instance. * Adds block support, which dosen't require a ID (works well with null). * - * @var int|null + * @var int|string|null */ public $ID = null; @@ -188,6 +188,7 @@ public function __construct( $this->args = $args; $this->ID = $post->ID ?? null; + $this->postStatus = $post->post_status ?? 'publish'; $this->init(); @@ -338,7 +339,7 @@ protected function getID(): int|string|null $id = acf_get_valid_post_id( false ); } - return $id ?: null; + return $this->ID = $id ?: null; } /** @@ -347,10 +348,7 @@ protected function getID(): int|string|null */ protected function getFields() { $this->dataFetched = true; - if(is_numeric($this->ID)) { - return AcfService::get()->getFields($this->ID) ?: []; - } - return AcfService::get()->getFields() ?: []; //Blocks + return AcfService::get()->getFields($this->getID()) ?: []; } private function getBlockNamesFromPage(): array