Skip to content

Gutenberg block

Phase 9 registers a dynamic block ad-form/form. The editor never executes the form (no ServerSideRender). Frontend output reuses [ad_form] / FormRenderer.

Block

KeyValue
Namead-form/form
Categorywidgets
Iconfeedback
AttributeformId (integer, default 0)
Supportshtml: false, align: wide|full, custom class, anchor

GutenbergIntegration registers the type on init (priority 20) when register_block_type exists and assets/build/block.asset.php is readable. Missing compiled assets skip block registration; ad_form_gutenberg_register still fires so add-ons can register their own types.

render_callback calls Shortcode::render( [ 'id' => $formId, 'source' => 'gutenberg' ] ). Empty formId or a missing form returns an empty string. Output is wrapped with get_block_wrapper_attributes() (wp-block-ad-form-form).

Entry source stored on submissions is gutenberg (column source, VARCHAR(50)).

Editor

Compiled from assets/src/block/ into assets/build/block.js and block.css with the same react/jsx-runtime bundling as the builder (WordPress 6.4 has no react-jsx-runtime handle).

The sidebar is a SelectControl of published forms. The canvas shows a placeholder or a preview card (title + shortcode) and a note that the live form appears on the published page.

Inline config window.adFormBlock:

json
{
  "canEditForms": true,
  "formsUrl": "…/wp-admin/admin.php?page=ad-form-forms"
}

Picker REST

GET /wp-json/ad-form/v1/forms/picker

Capability: edit_posts or edit_pages or edit_ad_form_forms or manage_ad_form_forms.

Query: optional search. Always status=published, per_page=100, orderby=title ASC.

Items are { id, title, slug, shortcode } only. No definition, UUID, or counts.

Frontend assets

Frontend\Assets::detect_from_query() treats both [ad_form] and <!-- wp:ad-form/form as a present form so CSS can print in wp_head. The render callback still calls mark_form_present() / enqueue() for widgets and late content; print_late in wp_footer covers that path.

PHP

  • Dingfelder\AdForm\Gutenberg\GutenbergIntegration
  • Dingfelder\AdForm\Gutenberg\GutenbergServiceProvider
  • Dingfelder\AdForm\REST\Permissions::pick_forms()
  • Dingfelder\AdForm\Forms\Form::to_picker_array()

Next

Phase 12: form templates.

Digitale Lösungen. Persönlich. Zukunftssicher.