| @@ -26,8 +26,11 @@ | ||
| 26 | 26 | |
| 27 | 27 | // Register this as a Gutenberg block in the ConvertKit Plugin. |
| 28 | 28 | add_filter( 'convertkit_blocks', array( $this, 'register' ) ); |
| 29 | 29 | |
| 30 | + // Register this block's MCP abilities. | |
| 31 | + add_filter( 'convertkit_abilities', array( $this, 'register_abilities' ) ); | |
| 32 | + | |
| 30 | 33 | // Enqueue scripts for this Gutenberg Block in the editor view. |
| 31 | 34 | add_action( 'convertkit_gutenberg_enqueue_scripts', array( $this, 'enqueue_scripts_editor' ) ); |
| 32 | 35 | |
| 33 | 36 | // Enqueue styles for this Gutenberg Block in the editor view. |
| @@ -101,8 +104,21 @@ | ||
| 101 | 104 | |
| 102 | 105 | } |
| 103 | 106 | |
| 104 | 107 | /** |
| 108 | + * Returns this block's plural title. | |
| 109 | + * | |
| 110 | + * @since 3.4.0 | |
| 111 | + * | |
| 112 | + * @return string | |
| 113 | + */ | |
| 114 | + public function get_title_plural() { | |
| 115 | + | |
| 116 | + return __( 'Kit Forms', 'convertkit' ); | |
| 117 | + | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 105 | 121 | * Returns this block's icon. |
| 106 | 122 | * |
| 107 | 123 | * @since 3.1.1 |
| 108 | 124 | */ |
| @@ -261,32 +277,44 @@ | ||
| 261 | 277 | * @return bool|array |
| 262 | 278 | */ |
| 263 | 279 | public function get_fields() { |
| 264 | 280 | |
| 265 | - // Get ConvertKit Forms. | |
| 281 | + // Get ConvertKit Forms. Non-legacy forms populate the sidebar dropdown; | |
| 282 | + // legacy forms are exposed separately as a fallback so the sidebar can | |
| 283 | + // keep displaying a previously-saved legacy form as the current | |
| 284 | + // selection without offering other legacy forms as new choices. | |
| 266 | 285 | $forms = array(); |
| 286 | + $legacy_forms = array(); | |
| 267 | 287 | $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' ); |
| 268 | 288 | if ( $convertkit_forms->exist() ) { |
| 269 | 289 | foreach ( $convertkit_forms->get() as $form ) { |
| 270 | - // Legacy forms don't include a `format` key, so define them as inline. | |
| 271 | - $forms[ absint( $form['id'] ) ] = sprintf( | |
| 290 | + $label = sprintf( | |
| 272 | 291 | '%s [%s]', |
| 273 | 292 | sanitize_text_field( $form['name'] ), |
| 293 | + // Legacy forms don't include a `format` key, so define them as inline. | |
| 274 | 294 | ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' ) |
| 275 | 295 | ); |
| 296 | + | |
| 297 | + if ( ! empty( $form['format'] ) ) { | |
| 298 | + $forms[ absint( $form['id'] ) ] = $label; | |
| 299 | + } else { | |
| 300 | + $legacy_forms[ absint( $form['id'] ) ] = $label; | |
| 301 | + } | |
| 276 | 302 | } |
| 277 | 303 | } |
| 278 | 304 | |
| 279 | 305 | return array( |
| 280 | 306 | 'form' => array( |
| 281 | - 'label' => __( 'Form', 'convertkit' ), | |
| 282 | - 'type' => 'resource', | |
| 283 | - 'resource' => 'forms', | |
| 284 | - 'values' => $forms, | |
| 285 | - 'data' => array( | |
| 307 | + 'label' => __( 'Form', 'convertkit' ), | |
| 308 | + 'type' => 'resource', | |
| 309 | + 'resource' => 'forms', | |
| 310 | + 'values' => $forms, | |
| 311 | + 'legacy_values' => $legacy_forms, | |
| 312 | + 'data' => array( | |
| 286 | 313 | // Used by resources/backend/js/gutenberg-block-form.js to determine the selected form's format |
| 287 | 314 | // (modal, slide in, sticky bar) and output a message in the block editor for the preview to explain |
| 288 | - // why some formats cannot be previewed. | |
| 315 | + // why some formats cannot be previewed. Includes legacy forms so the preview code can still find | |
| 316 | + // them when a saved block references a legacy form. | |
| 289 | 317 | 'forms' => ( $convertkit_forms->exist() ? $convertkit_forms->get() : array() ), |
| 290 | 318 | ), |
| 291 | 319 | ), |
| 292 | 320 | ); |