Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 1.58 KB

clone.mdx

File metadata and controls

72 lines (52 loc) · 1.58 KB

Clone

(CtrlField Pro)

Includes the fields from another registered field group or a preset. Useful for sharing a common set of fields across multiple groups.


PHP API

Field::clone(string $key): CloneField  // Pro

Type-specific methods

->from(string $groupKeyOrPreset): static

The key of a registered FieldGroup or FieldPresets preset to clone from.

->prefix(string $prefix): static

Prefix all cloned field keys to avoid collisions. e.g. prefix('hero_') makes title → hero_title.

->display(string $mode): static

'seamless' (default) — fields appear inline. 'group' — fields appear inside a sub-group UI.


Storage

Cloned fields are stored as if they were declared directly in the group. No nesting.

{ "hero_title": "Welcome", "hero_subtitle": "We build things" }

Example

// Define shared fields once
Field::group('seo_fields')
    ->where('post_type', '==', '_internal_seo')
    ->fields([
        Field::text('seo_title')->label('SEO Title'),
        Field::textarea('seo_description')->label('SEO Description'),
        Field::image('og_image')->label('OG Image'),
    ])
    ->register();

// Clone into your group
Field::group('portfolio_details')
    ->where('post_type', '==', 'portfolio')
    ->fields([
        Field::text('client_name'),
        Field::clone('seo')->from('seo_fields'),
    ])
    ->register();

Notes

  • The source group must be registered before the group containing the Clone field.
  • Avoid circular clones (group A cloning group B which clones group A).