Skip to content

Notes for Fields API refactor #99

@danieliser

Description

@danieliser

/**
 * New v2.2 fields method should account for.
 *
 * - Id
 * - Tab
 * - Section/panel
 * - Priority
 * - Component/Slot
 * - Component props
 *
 * Tab & section sorting default to order of registration.
 * - Add filter to allow custom sorting.
 *
 * Should allow passing fields, props, and an options object through the filter.
 * - Fields should be an array of objects.
 * - Props should be an object containing settings, updateSettings.
 * - Options should be an object containing additional info such as:
 * 	 - Shared instanceId.
 *   - fieldIsVisible method
 *   - tabIsVisible method
 *   - sectionIsVisible method
 * - Should return an array of objects.
 *
 * New helper methods should account for:
 * - getFields should be modified to accept tab & section filters.
 *   - Sort fields by priority after filtering.
 * - sortFields should sort by tab (priority) => section (priority) => field (priority)
 * - tabIsVisible
 * - sectionIsVisible
 */
addFilter(
	'contentControl.restrictionEditor.fields',
	'content-control',
	( fields, { settings, updateSettings }, options ) => {
		return [
			...fields,
			{
				id: 'protectionMethod',
				tab: 'protection',
				section: 'general',
				priority: 1,
				component: (
					<RadioButtonControl
						label={ __(
							'How do you want to protect your content?',
							'content-control'
						) }
						value={ settings.protectionMethod }
						onChange={ ( protectionMethod ) =>
							updateSettings( { protectionMethod } )
						}
						options={ ( () =>
							applyFilters(
								'contentControl.restrictionEditor.protectionMethodOptions',
								protectionMethodOptions
							) as typeof protectionMethodOptions )() }
					/>
				),
			},
			{
				id: 'protectionFieldsSlot',
				tab: 'protection',
				section: '',
				priority: 2,
				component: <ProtectionFieldsSlot />,
			},
		];
	}
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions