folbert / fewbricks

Write code to create ACF field groups, fields and re-usable modules.
https://fewbricks2.folbert.com
GNU General Public License v3.0
124 stars 12 forks source link

Repeater within flex content #28

Closed zackphilipps closed 7 years ago

zackphilipps commented 7 years ago

Hi @folbert ! Great work, this is awesome stuff.

I am running into a slight issue, which is that there seems to be no way to "terminate" a Repeater within a Flexible Content field.

See screenshot: http://jmp.sh/AlEg9Wf

The last three tabs there are actually supposed to be part of the next Layout. But since the code is just add_sub_field over and over, it appears to just tack them on to the Repeater:

# =============================================================================>
# 5. 25/75 Image and Text
# =============================================================================>
$l = new layout( '5. 25/75 Image and Text', 'image_text_25_75', '201704051323a' );

// Content tab
$l->add_sub_field(
  new acf_fields\tab(
    'Content', '', '201704051323b', [
      'placement' => 'top',
      'endpoint' => 0,
    ]
  )
);

$repeater = (
  new acf_fields\repeater(
    '25/75 Image and Text', 'image_text_25_75_row', '201704051335a', [
      'min' => 1,
      'max' => 6,
      'layout' => 'block',
      'button_label' => 'Add Row',
    ]
  )
);

$repeater->add_sub_field(
  new acf_fields\radio(
    'Image Position', 'image_position', '201704051341a', [
      'wrapper' => [
        'width' => '50'
      ],
      'choices' => [
        'left' => 'Left',
        'right' => 'Right',
      ],
      'layout' => 'horizontal',
      'return_format' => 'value'
    ]
  )
);

$l->add_sub_field( $repeater );

// Styles tab
$l->add_sub_field(
  new acf_fields\tab(
    'Styles', '', '201704051353a', [
      'placement' => 'top',
      'endpoint' => 0,
    ]
  )
);

$l->add_brick( new colors( 'colors', '201704051253b' ) );

$fc->add_layout( $l );

# =============================================================================>
# 7. 50/50 Text
# =============================================================================>
$l = new layout( '7. 50/50 Text', 'text_50_50', '201704051323a' );

$l->add_sub_field(
  new acf_fields\radio(
    'Headline Format', 'headline_format', '201704051355a', [
      'instructions' => '<span style="font-size:11px; font-style:italic;">If single headline, headline will be centered over both columns. If two headlines, each headline will be aligned left over their respective columns.</span>',
      'choices' => array (
        'one' => 'Single',
        'two' => 'Double',
      ),
      'default_value' => 'one : Single',
      'layout' => 'vertical',
      'return_format' => 'value',
    ]
  )
);

// Left Side tab
$l->add_sub_field(
  new acf_fields\tab(
    'Left Side', '', '201704051428a', [
      'placement' => 'top',
      'endpoint' => 0,
    ]
  )
);

$l->add_sub_field(
  new acf_fields\text(
    'Left Headline', 'left_headline', '201704051432a', [
      'conditional_logic' => array (
        array (
          array (
            'field' => '201704051355a',
            'operator' => '==',
            'value' => 'two',
          ),
        ),
      ),
    ]
  )
);

$l->add_sub_field(
  new acf_fields\wysiwyg(
    'Left Content', 'left_content', '201704051434a'
  )
);

// Right Side tab
$l->add_sub_field(
  new acf_fields\tab(
    'Right Side', '', '201704051435a', [
      'placement' => 'top',
      'endpoint' => 0,
    ]
  )
);

$l->add_sub_field(
  new acf_fields\text(
    'Right Headline', 'right_headline', '201704051435b', [
      'conditional_logic' => array (
        array (
          array (
            'field' => '201704051355a',
            'operator' => '==',
            'value' => 'two',
          ),
        ),
      ),
    ]
  )
);

$l->add_sub_field(
  new acf_fields\wysiwyg(
    'Right Content', 'right_content', '201704051435c'
  )
);

// Styles tab
$l->add_sub_field(
  new acf_fields\tab(
    'Styles', '', '201704051436a', [
      'placement' => 'top',
      'endpoint' => 0,
    ]
  )
);

$l->add_brick( new colors( 'colors', '201704051441b' ) );

$fc->add_layout( $l );

Note: When adding the Repeater to the Layout, I have tried both add_sub_field and add_repeater, and both produce the same result.

zackphilipps commented 7 years ago

I figured this out... I had one tiny duplicate field key. :)