Skip to content

Conditionals referencing parent fields

Compare
Choose a tag to compare
@stevep stevep released this 12 Feb 17:17
· 20 commits to master since this release
06f5903

You can now write conditionals that reference fields not on the same level. [Issue: #52]

You can either just reference the name of the parent field:

$builder = new \StoutLogic\AcfBuilder\FlexibleContentBuilder('sections');
$builder
  ->addLayout('hero')
  ->addSelect('hero_type')
  ->addChoices('fullscreen', 'standard')
  ->addImage( 'hero_image' )
  ->addWysiwyg( 'hero_text' )
  ->addRepeater('cta')
    ->addSelect('link_type')
    ->addChoices('internal', 'external', 'text')
    ->addTrueFalse('cta_animated')
      ->conditional('hero_type', '==', 'fullscreen');

Or you can set a custom key

$builder = new \StoutLogic\AcfBuilder\FlexibleContentBuilder('sections');
$builder
  ->addLayout('hero')
  ->addSelect('hero_type')
  ->addChoices('fullscreen', 'standard')
    ->setCustomKey('my_custom_key')
  ->addImage( 'hero_image' )
  ->addWysiwyg( 'hero_text' )
  ->addRepeater('cta')
    ->addSelect('link_type')
    ->addChoices('internal', 'external', 'text')
    ->addTrueFalse('cta_animated')
      ->conditional('my_custom_key', '==', 'fullscreen');

This shouldn't break backwards compatibility, I've tested it on my professional projects. But if you do run into issues, let me know ASAP.

Other additions include:

  • #130 Fix Intelephense's Undefined method
  • Setup testing via GitHub actions for php versions 5.4 - 7.4. The version of PHP unit being used isn't supported for PHP 8.0 so it is untested. If you run into any issues in the wild, while testing on 8.0, let me know.