Email_Notifications::get_dynamic_template_tags( awsmug\Torro_Forms\DB_Objects\Forms\Form $form, bool $back_compat = false )

Gets all the dynamic template tags for a form, consisting of the form’s element value tags.

Description

Parameters

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form for which to get the dynamic template tags.

$back_compat

(bool) (Optional) Whether to also include back-compat keys for Torro Forms before 1.0.0-beta.9.

Default value: false

Return

(array) Dynamic tags as <code>$slug => $data</code> pairs.

Source

File: src/modules/actions/email-notifications.php

	protected function get_dynamic_template_tags( $form, $back_compat = false ) {
		$tags = array();

		foreach ( $form->get_elements() as $element ) {
			$element_type = $element->get_element_type();
			if ( ! $element_type ) {
				continue;
			}

			$tags[ 'value_element_' . $element->id ] = array(
				'group'       => 'submission',
				/* translators: %s: element label */
				'label'       => sprintf( __( 'Value for &#8220;%s&#8221;', 'torro-forms' ), $element->label ),
				/* translators: %s: element label */
				'description' => sprintf( __( 'Inserts the submission value for the element &#8220;%s&#8221;.', 'torro-forms' ), $element->label ),
				'callback'    => function( $form, $submission ) use ( $element, $element_type ) {
					$element_values = $submission->get_element_values_data();
					if ( ! isset( $element_values[ $element->id ] ) ) {
						return '';
					}

					$export_values = $element_type->format_values_for_export( $element_values[ $element->id ], $element, 'html' );
					if ( ! isset( $export_values[ 'element_' . $element->id . '__main' ] ) ) {
						if ( count( $export_values ) !== 1 ) {
							return '';
						}

						return array_pop( $export_values );
					}

					return $export_values[ 'element_' . $element->id . '__main' ];
				},
			);

			// Add email support to text fields with input_type 'email_address'.
			if ( is_a( $element_type, Textfield::class ) ) {
				$settings = $element_type->get_settings( $element );
				if ( ! empty( $settings['input_type'] ) && 'email_address' === $settings['input_type'] ) {
					$tags[ 'value_element_' . $element->id ]['email_support'] = true;
				}
			}

			if ( $back_compat ) {
				$tags[ $element->label . ':' . $element->id ] = $tags[ 'value_element_' . $element->id ];
			}
		}

		return $tags;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.