| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | namespace Jet_Form_Builder\Form_Messages; |
| 5 | 5 | |
| 6 | 6 | // If this file is called directly, abort. |
| 7 | 7 | use Jet_Form_Builder\Classes\Get_Template_Trait; |
| 8 | -use JFB_Modules\Rich_Content; | |
| 9 | 8 | |
| 10 | 9 | if ( ! defined( 'WPINC' ) ) { |
| 11 | 10 | die; |
| 12 | 11 | } |
| @@ -20,8 +19,13 @@ | ||
| 20 | 19 | |
| 21 | 20 | private $status; |
| 22 | 21 | |
| 23 | 22 | /** |
| 23 | + * @var Message_Content_Processor | |
| 24 | + */ | |
| 25 | + private $content_processor; | |
| 26 | + | |
| 27 | + /** | |
| 24 | 28 | * Set form submittion status |
| 25 | 29 | * |
| 26 | 30 | * @param [type] $status [description] |
| 27 | 31 | * |
| @@ -48,10 +52,20 @@ | ||
| 48 | 52 | |
| 49 | 53 | return $this->status; |
| 50 | 54 | } |
| 51 | 55 | |
| 56 | + public function prepare_message_content( string $message ): string { | |
| 57 | + return $this->get_content_processor()->prepare_macros( | |
| 58 | + $message, | |
| 59 | + jet_fb_context()->get_request() | |
| 60 | + ); | |
| 61 | + } | |
| 62 | + | |
| 52 | 63 | public function render_empty_field_message() { |
| 53 | - $message_content = $this->get_manager()->get_message( 'empty_field' ); | |
| 64 | + $message_content = $this->get_content_processor()->prepare_trusted( | |
| 65 | + $this->get_manager()->get_message( 'empty_field' ), | |
| 66 | + jet_fb_context()->get_request() | |
| 67 | + ); | |
| 54 | 68 | |
| 55 | 69 | include $this->get_global_template( 'common/field-message.php' ); |
| 56 | 70 | } |
| 57 | 71 | |
| @@ -66,11 +80,22 @@ | ||
| 66 | 80 | if ( ! $status ) { |
| 67 | 81 | return; |
| 68 | 82 | } |
| 69 | 83 | |
| 70 | - $info = new Status_Info( $status ); | |
| 71 | - $message_content = Rich_Content\Module::rich( $this->get_manager()->get_message_by_info( $info ) ); | |
| 84 | + $info = new Status_Info( $status ); | |
| 85 | + $manager = $this->get_manager(); | |
| 86 | + $message = $manager->get_message_by_info( $info ); | |
| 72 | 87 | |
| 88 | + // Only a registered key resolves to a template stored in form/action settings. | |
| 89 | + if ( ! $info->is_dynamic() && $manager->isset_message_type( $info->get_message() ) ) { | |
| 90 | + $message_content = $this->get_content_processor()->prepare_trusted( | |
| 91 | + $message, | |
| 92 | + jet_fb_context()->get_request() | |
| 93 | + ); | |
| 94 | + } else { | |
| 95 | + $message_content = $this->get_content_processor()->prepare_untrusted( $message ); | |
| 96 | + } | |
| 97 | + | |
| 73 | 98 | $class = 'jet-form-builder-message'; |
| 74 | 99 | $class .= ' jet-form-builder-message--' . $info->get_css_class(); |
| 75 | 100 | |
| 76 | 101 | include $this->get_global_template( 'common/messages.php' ); |
| @@ -96,8 +121,16 @@ | ||
| 96 | 121 | ob_start(); |
| 97 | 122 | $this->render_messages(); |
| 98 | 123 | |
| 99 | 124 | return ob_get_clean(); |
| 125 | + } | |
| 126 | + | |
| 127 | + public function get_content_processor(): Message_Content_Processor { | |
| 128 | + if ( is_null( $this->content_processor ) ) { | |
| 129 | + $this->content_processor = new Message_Content_Processor(); | |
| 130 | + } | |
| 131 | + | |
| 132 | + return $this->content_processor; | |
| 100 | 133 | } |
| 101 | 134 | |
| 102 | 135 | |
| 103 | 136 | } |