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.
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
Return Return
(array[])
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; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |