GF_SUBFORM_CODES::validate_conditions( $args )

Validate if trigger matches the condition.


Parameters Parameters

$args

(Required)


Top ↑

Return Return

(array)


Source Source

File: src/integrations/gravity-forms/triggers/gf-subform-codes.php

	protected function validate_conditions( $args ) {

		$matched_recipe_ids = array();

		list ( $entry, $form ) = $args;

		if ( empty( $entry ) || empty( $form ) ) {
			return $matched_recipe_ids;
		}

		$recipes = $this->trigger_recipes();

		if ( empty( $recipes ) ) {
			return $matched_recipe_ids;
		}

		$required_form  = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );
		$required_batch = Automator()->get->meta_from_recipes( $recipes, sprintf( '%s_CODES', $this->trigger_meta ) );

		if ( empty( $required_form ) ) {
			return $matched_recipe_ids;
		}

		$code_fields = Gravity_Forms_Helpers::get_code_fields( $entry, $form );

		// Bailout if there are no UncannyCodes fields in the form.
		if ( empty( $code_fields ) ) {
			return $matched_recipe_ids;
		}

		$form_id = $form['id'];

		foreach ( $recipes as $recipe_id => $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {
				$trigger_id = absint( $trigger['ID'] );
				if ( ! isset( $required_form[ $recipe_id ] ) ) {
					continue;
				}
				if ( ! isset( $required_form[ $recipe_id ][ $trigger_id ] ) ) {
					continue;
				}

				$code_field = array_shift( $code_fields );
				if ( empty( $code_field ) || null === $code_field ) {
					continue;
				}
				$batch = Gravity_Forms_Helpers::get_batch_by_value( $code_field, $entry );

				if (
					absint( $form_id ) === absint( $required_form[ $recipe_id ][ $trigger_id ] ) &&
					(
						intval( '-1' ) === intval( $required_batch[ $recipe_id ][ $trigger_id ] ) ||
						absint( $batch->code_group ) === absint( $required_batch[ $recipe_id ][ $trigger_id ] )
					)
				) {
					$matched_recipe_ids[ $recipe_id ] = $trigger_id;
				}
			}
		}

		return $matched_recipe_ids;

	}