Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Forms::cascade_visibility_attrs( array[] $blocks, string|null $visibility = null )

Cascade all llms_visibility attributes down into inner blocks.


Description Description

If a parent block has a visibility setting this will apply that visibility to a chlid block if the child block does not have a visibility setting of its own.

Ultimately this ensures that a field block that’s not visible can be marked as "optional" so that form validation can take place.

For example, if a columns block is displayed only to logged out users and it’s child fields are marked as required that means that it’s required only to logged out users and the field becomes "optional" (for validation purposes) to logged in users.


Top ↑

Parameters Parameters

$blocks

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

$visibility

(string|null) (Optional) The llms_visibility attribute of the parent block which is applied to all innerBlocks if the innerBlock does not already have it's own visibility attribute.

Default value: null


Top ↑

Return Return

(array[])


Top ↑

Source Source

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

	private function cascade_visibility_attrs( $blocks, $visibility = null ) {

		foreach ( $blocks as &$block ) {

			// If a visibility setting has been passed from the parent and the block does not have visibility setting of it's own.
			if ( $visibility && ( empty( $block['attrs']['llms_visibility'] ) || 'off' === $block['attrs']['llms_visibility'] ) ) {
				$block['attrs']['llms_visibility'] = $visibility;
			}

			// This block has a visibility attribute and it should be applied it to all the innerBlocks.
			if ( ! empty( $block['attrs']['llms_visibility'] ) && ! empty( $block['innerBlocks'] ) ) {
				$block['innerBlocks'] = $this->cascade_visibility_attrs( $block['innerBlocks'], $block['attrs']['llms_visibility'] );
			}
		}

		return $blocks;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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