twig = $twig; $this->cptData = $cptData; $this->html = $markup; $this->twigVariables = []; } abstract protected function setTwigVariables(bool $isForValidation = false): void; abstract protected function renderTwig(bool $isForValidation = false): void; public function getMarkupValidationError(): string { $this->setTwigVariables(true); $this->renderTwig(true); preg_match('/(.*)$/', $this->html, $errorMessage); $errorMessage = $errorMessage[1] ?? ''; $errorMessage = str_replace('', '', $errorMessage); $errorMessage = trim($errorMessage); return $errorMessage; } }