diff --git a/modules/template/elements/BaseElementVariable.php b/modules/template/elements/BaseElementVariable.php index 23ebcadc..908d0436 100644 --- a/modules/template/elements/BaseElementVariable.php +++ b/modules/template/elements/BaseElementVariable.php @@ -67,7 +67,7 @@ public function render(bool $editMode = false): string 'default' => $this->elementContent->isDefault(), ], $this->options); - $options['template_instance_type'] = TemplateInstance::getTypeById($options['template_instance_id']); + $options['template_instance_type'] = $this->elementContent->templateInstance?->getType(); // We only need the template_id for container content elements if ($this->elementContent instanceof ContainerElement) { diff --git a/modules/template/models/TemplateInstance.php b/modules/template/models/TemplateInstance.php index c538b0bc..0edea695 100644 --- a/modules/template/models/TemplateInstance.php +++ b/modules/template/models/TemplateInstance.php @@ -25,6 +25,11 @@ */ class TemplateInstance extends ActiveRecord { + + const TYPE_PAGE = 'page'; + const TYPE_CONTAINER = 'container'; + + /** * @inheritdoc */ @@ -146,13 +151,8 @@ public function getRoot(): ?self return self::findOne(['page_id' => $this->page_id, 'container_item_id' => null]); } - public static function getTypeById($id): string - { - $instance = self::findOne($id); - if ($instance === null) { - return ''; - } - - return $instance->container_item_id === null ? 'page' : 'container'; + public function getType() { + return $this->container_item_id === null ? self::TYPE_PAGE : self::TYPE_CONTAINER; } + }