is_formatted_value_in_use = $is_formatted_value_in_use; $this->is_with_replace_new_line_to_br = $is_with_replace_new_line_to_br; } public function print_markup( string $field_id, Markup_Field_Data $markup_field_data ): void { $var = $markup_field_data->get_token_factory()->variable( $field_id ) ->add_item_path( 'value' ); $markup_field_data->get_token_factory()->to_echo( $var ) ->set_is_raw( true ) ->print(); } /** * @return array */ public function get_template_variables( Variable_Field_Data $variable_field_data ): array { $twig_args = array( 'value' => '', 'raw_value' => '', ); // by default use the formatted value, as we need html (e.g. for oembed) instead of the pure value. $value = $this->is_formatted_value_in_use ? $variable_field_data->get_formatted_value() : $variable_field_data->get_value(); $value = is_string( $value ) || is_numeric( $value ) ? (string) $value : ''; $value = $this->is_with_replace_new_line_to_br ? str_replace( "\n", '
', $value ) : $value; return array_merge( $twig_args, array( 'value' => $value, // always provide the raw value alongside with the current, // e.g. in oEmbed case, it allows to get the url instead of the iframe's html. 'raw_value' => $variable_field_data->get_value(), ) ); } /** * @return array */ public function get_validation_template_variables( Variable_Field_Data $variable_field_data ): array { return array( 'value' => '1', 'raw_value' => '1', ); } public function is_with_field_wrapper( Layout_Settings $layout_settings, Field_Settings $field_settings, Field_Meta $field_meta ): bool { return true; } }