twig = $twig; $this->cpt_data = $cpt_data; $this->twig_template = $twig_template; $this->classes = $classes; } /** * @return array */ abstract protected function get_twig_variables( bool $is_for_validation = false ): array; /** * @param array $twig_variables */ abstract protected function render_twig_and_print_html( string $twig_template, array $twig_variables, bool $is_for_validation = false ): bool; protected function get_classes(): string { $classes = ''; $classes .= '' !== $this->classes ? $this->classes . ' ' : ''; $classes .= '' !== $this->cpt_data->css_classes ? $this->cpt_data->css_classes . ' ' : ''; return $classes; } protected function get_twig(): Twig { return $this->twig; } protected function get_twig_template(): string { return $this->twig_template; } protected function set_twig_template( string $twig_template ): void { $this->twig_template = $twig_template; } public function get_markup_validation_error(): string { $twig_variables_for_validation = $this->get_twig_variables( true ); ob_start(); $this->render_twig_and_print_html( $this->twig_template, $twig_variables_for_validation, true ); $html = (string) ob_get_clean(); preg_match( '/(.*)$/', $html, $error_message ); $error_message = $error_message[1] ?? ''; $error_message = str_replace( '', '', $error_message ); $error_message = trim( $error_message ); return $error_message; } /** * @return array */ public function get_twig_variables_for_validation(): array { return $this->get_twig_variables( true ); } }