LLMS_Forms_Dynamic_Fields::maybe_add_required_block_fields( array[] $blocks, string $location, array $args )

Maybe add the required email and password block to a form


Parameters Parameters

$blocks

(array[]) (Required) Array of parsed WP_Block arrays.

$location

(string) (Required) The request form location ID.

$args

(array) (Required) Additional arguments passed to the short-circuit filter.


Top ↑

Return Return

(array[])


Top ↑

Source Source

File: includes/forms/class-llms-forms-dynamic-fields.php

	public function maybe_add_required_block_fields( $blocks, $location, $args ) {

		$fields_to_require = $this->get_required_fields_for_location( $location, $args );
		if ( empty( $fields_to_require ) ) {
			return $blocks;
		}

		foreach ( $fields_to_require as $field_id => $field_block_name ) {

			$block = $this->find_block( $field_id, $blocks );

			if ( ! empty( $block ) ) {
				// Fields in non checkout forms are always visible - see LLMS_Forms::get_form_html().
				$blocks = 'checkout' === $location ? $this->make_block_visible( $block[1], $blocks, $block[0] ) : $blocks;
				unset( $fields_to_require[ $field_id ] );
				if ( empty( $fields_to_require ) ) { // All the required blocks are present.
					return $blocks;
				}
			}
		}

		$blocks_to_add = array();
		foreach ( $fields_to_require as $field_id => $block_to_add ) {
			// If a reusable block exists for the field, use it. Otherwise use a dynamically generated block from the template schema.
			$use_reusable    = LLMS_Form_Templates::find_reusable_block( $block_to_add ) ? true : false;
			$blocks_to_add[] = LLMS_Form_Templates::get_block( $block_to_add, $location, $use_reusable );
		}

		// Load reusable.
		$blocks_to_add = LLMS_Forms::instance()->load_reusable_blocks( $blocks_to_add );
		// Make blocks to add visible.
		$blocks_to_add = 'checkout' === $location ? array_map( array( $this, 'make_all_visible' ), $blocks_to_add ) : $blocks_to_add;

		return array_merge(
			$blocks,
			$blocks_to_add
		);

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.