From aae9181cfc40f3bc8c1c3cf9d73a683dc53c55d1 Mon Sep 17 00:00:00 2001 From: sgillot Date: Thu, 10 Sep 2026 10:21:32 +0200 Subject: [PATCH 1/2] fix: resolve missing collection during icon-block migration Legacy blocks with an icon name but no collection were skipped entirely. Look up the name in registered collections, then fall back to mediatheque or icon-pack, and bump to 1.1.2. Co-authored-by: Cursor --- .plugin-data | 2 +- CHANGELOG.md | 4 ++ MIGRATION.md | 4 +- blockparty-icons.php | 4 +- includes/Migration/IconBlockMigrator.php | 63 ++++++++++++++++++++++-- package-lock.json | 4 +- package.json | 2 +- readme.txt | 5 +- src/block.json | 2 +- 9 files changed, 75 insertions(+), 15 deletions(-) diff --git a/.plugin-data b/.plugin-data index 91edf44..80a8f24 100644 --- a/.plugin-data +++ b/.plugin-data @@ -1,4 +1,4 @@ { - "version": "1.1.1", + "version": "1.1.2", "slug": "blockparty-icons" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4756984..f4ba589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ This plugin **doesn't run any sanitization on SVGs** before using them. Only use ## Changelog +### 1.1.2 - 2026-09-10 + +- Fix `beapi/icon-block` migration skipping icons that have a name but no collection (registry lookup then generic fallback) + ### 1.1.1 - 2026-08-26 - Fix deprecated warning for nullable string parameters in `CollectionItem` diff --git a/MIGRATION.md b/MIGRATION.md index 35b1bad..a96f1d0 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -56,7 +56,7 @@ You can also pass a `Collection` instance built with `Collection::from_sprite()` | Old (`icon-item` / legacy parent) | New (`blockparty/icon`) | |---|---| -| `icon` (`name`, `type`, `label`, optional `collection`) | `icon` (requires `collection` + `name`) | +| `icon` (`name`, `type`, `label`, optional `collection`) | `icon` (`collection` + `name`; collection is looked up / fallen back when missing) | | Parent `collection.name` (legacy object) | `icon.collection` | | `iconColorValue` / legacy `iconColor.color` | `iconColor` (value kept as-is, including `inherit`) | | `size` (int) | `size` (int) | @@ -98,7 +98,7 @@ The command: 4. Logs migrated / skipped counts 5. Lists missing icon assets (`collection/name`) so you can add them manually to theme assets / collections -When `collection` is missing on the icon object (and not on the parent attrs), the block is skipped — there is no default collection. Missing files among converted icons are reported, not skipped. +When `collection` is missing on the icon object (and not on the parent attrs) but `name` is present, the migrator looks up that name in registered collections (preferred order: `icon-pack`, `theme`, `mediatheque`, then the rest). If still unresolved, it falls back to `mediatheque` for `raw` icons and `icon-pack` otherwise (`sprite` is inferred from `` in the saved HTML when `type` is absent). The block is skipped only when `name` (or collection after these steps) is still missing. Missing files among converted icons are reported as CLI warnings, not skipped. ### Revisions diff --git a/blockparty-icons.php b/blockparty-icons.php index c294308..b2dab2c 100644 --- a/blockparty-icons.php +++ b/blockparty-icons.php @@ -4,7 +4,7 @@ * Description: Provides blocks in WordPress editor to add custom SVG icons. * Requires at least: 6.2 * Requires PHP: 8.1 - * Version: 1.1.1 + * Version: 1.1.2 * Author: Be API Technical Team * Author URI: https://beapi.fr * License: GPL-2.0-or-later @@ -30,7 +30,7 @@ include_once __DIR__ . '/vendor/autoload.php'; } -define( 'BLOCKPARTY_ICONS_VERSION', '1.1.1' ); +define( 'BLOCKPARTY_ICONS_VERSION', '1.1.2' ); define( 'BLOCKPARTY_ICONS_URL', plugin_dir_url( __FILE__ ) ); define( 'BLOCKPARTY_ICONS_DIR', plugin_dir_path( __FILE__ ) ); define( 'BLOCKPARTY_ICONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); diff --git a/includes/Migration/IconBlockMigrator.php b/includes/Migration/IconBlockMigrator.php index d0d19e6..9341014 100644 --- a/includes/Migration/IconBlockMigrator.php +++ b/includes/Migration/IconBlockMigrator.php @@ -202,7 +202,7 @@ private function convert_old_block( array $block ): array { * @param array $attrs Source attrs (item or legacy parent). * @param array $parent_attrs Parent attrs (for className / collection). * @param string $html Saved HTML of the old block. - * @return array|null Null when an icon was expected but name or collection is missing. + * @return array|null Null when an icon was expected but name or collection is still missing after lookup/fallback. * @author Jules Fell */ private function build_blockparty_block( array $attrs, array $parent_attrs, string $html ): ?array { @@ -222,14 +222,26 @@ private function build_blockparty_block( array $attrs, array $parent_attrs, stri // empty shells must become empty blockparty/icon blocks. $expects_icon = ( '' !== $name || $old_icon ); - // Collection from attrs only (no registry lookup, no project-specific default). + $type = (string) ( $old_icon['type'] ?? ( false !== strpos( $html, 'resolve_collection_for_icon( $name ); + } + + // Last resort: frequent BeAPI collection names (not project-specific). + if ( '' === $collection && '' !== $name ) { + $collection = 'raw' === $type ? 'mediatheque' : 'icon-pack'; + } + + // Abort only when an icon was expected but name or collection is still missing. if ( $expects_icon && ( '' === $name || '' === $collection ) ) { return null; } @@ -237,8 +249,6 @@ private function build_blockparty_block( array $attrs, array $parent_attrs, stri $new = []; if ( '' !== $name ) { - $type = (string) ( $old_icon['type'] ?? ( false !== strpos( $html, ' $collection, 'name' => $name, @@ -326,6 +336,49 @@ private function build_blockparty_block( array $attrs, array $parent_attrs, stri ]; } + /** + * Find the first registered collection that contains the given icon name. + * + * Preferred order: icon-pack, theme, mediatheque, then remaining collections. + * + * @param string $name Icon name. + * @return string Collection name, or empty string if none match. + */ + private function resolve_collection_for_icon( string $name ): string { + if ( ! function_exists( '\\Blockparty\\Icons\\get_icon_collections' ) ) { + return ''; + } + + $collections = \Blockparty\Icons\get_icon_collections(); + if ( empty( $collections ) ) { + return ''; + } + + $preferred = [ 'icon-pack', 'theme', 'mediatheque' ]; + $ordered = []; + + foreach ( $preferred as $preferred_name ) { + if ( isset( $collections[ $preferred_name ] ) ) { + $ordered[] = $collections[ $preferred_name ]; + } + } + + foreach ( $collections as $collection_name => $collection ) { + if ( in_array( $collection_name, $preferred, true ) ) { + continue; + } + $ordered[] = $collection; + } + + foreach ( $ordered as $collection ) { + if ( $collection->get( $name ) ) { + return $collection->name(); + } + } + + return ''; + } + /** * Record a migrated icon that is not available in registered collections. * diff --git a/package-lock.json b/package-lock.json index aa22b2a..12e4c07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "blockparty-icons", - "version": "1.1.1", + "version": "1.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "blockparty-icons", - "version": "1.1.1", + "version": "1.1.2", "license": "GPL-2.0-or-later", "dependencies": { "@beapi/icons": "^1.2.5", diff --git a/package.json b/package.json index 0c18322..1b47ddb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockparty-icons", - "version": "1.1.1", + "version": "1.1.2", "description": "Provides blocks in WordPress editor to add custom SVG icons from your theme.", "author": "Be API Technical team", "license": "GPL-2.0-or-later", diff --git a/readme.txt b/readme.txt index 3c5ef0a..9125819 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: block, icons, svg, gutenberg, editor Requires at least: 6.2 Tested up to: 6.8 Requires PHP: 8.1 -Stable tag: 1.1.1 +Stable tag: 1.1.2 License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -36,6 +36,9 @@ Yes. Register a collection with `type` set to `folder` and `source` pointing to == Changelog == += 1.1.2 = +* Resolve missing `icon.collection` during `beapi/icon-block` migration via registry lookup and a generic fallback. + = 1.1.1 = * Fix deprecated warning for nullable string parameters in `CollectionItem`. * Align GitHub workflows with other blockparty repos and add release version consistency checks. diff --git a/src/block.json b/src/block.json index ffd022b..d447f27 100644 --- a/src/block.json +++ b/src/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "blockparty/icon", - "version": "1.1.1", + "version": "1.1.2", "title": "Icon", "category": "widgets", "description": "Easily add custom vector icon to your content.", From f4ff8c4e30c27a99e56a9dd9792f72662fef4d89 Mon Sep 17 00:00:00 2001 From: sgillot Date: Thu, 17 Sep 2026 14:21:18 +0200 Subject: [PATCH 2/2] chore: drop the 1.1.2 version bump from this branch Keep the icon-block migration fix only; the release number and changelog will be added later. Co-authored-by: Cursor --- .plugin-data | 2 +- CHANGELOG.md | 4 ---- blockparty-icons.php | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- readme.txt | 5 +---- src/block.json | 2 +- 7 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.plugin-data b/.plugin-data index 80a8f24..91edf44 100644 --- a/.plugin-data +++ b/.plugin-data @@ -1,4 +1,4 @@ { - "version": "1.1.2", + "version": "1.1.1", "slug": "blockparty-icons" } diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ba589..4756984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,6 @@ This plugin **doesn't run any sanitization on SVGs** before using them. Only use ## Changelog -### 1.1.2 - 2026-09-10 - -- Fix `beapi/icon-block` migration skipping icons that have a name but no collection (registry lookup then generic fallback) - ### 1.1.1 - 2026-08-26 - Fix deprecated warning for nullable string parameters in `CollectionItem` diff --git a/blockparty-icons.php b/blockparty-icons.php index b2dab2c..c294308 100644 --- a/blockparty-icons.php +++ b/blockparty-icons.php @@ -4,7 +4,7 @@ * Description: Provides blocks in WordPress editor to add custom SVG icons. * Requires at least: 6.2 * Requires PHP: 8.1 - * Version: 1.1.2 + * Version: 1.1.1 * Author: Be API Technical Team * Author URI: https://beapi.fr * License: GPL-2.0-or-later @@ -30,7 +30,7 @@ include_once __DIR__ . '/vendor/autoload.php'; } -define( 'BLOCKPARTY_ICONS_VERSION', '1.1.2' ); +define( 'BLOCKPARTY_ICONS_VERSION', '1.1.1' ); define( 'BLOCKPARTY_ICONS_URL', plugin_dir_url( __FILE__ ) ); define( 'BLOCKPARTY_ICONS_DIR', plugin_dir_path( __FILE__ ) ); define( 'BLOCKPARTY_ICONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); diff --git a/package-lock.json b/package-lock.json index 12e4c07..aa22b2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "blockparty-icons", - "version": "1.1.2", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "blockparty-icons", - "version": "1.1.2", + "version": "1.1.1", "license": "GPL-2.0-or-later", "dependencies": { "@beapi/icons": "^1.2.5", diff --git a/package.json b/package.json index 1b47ddb..0c18322 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockparty-icons", - "version": "1.1.2", + "version": "1.1.1", "description": "Provides blocks in WordPress editor to add custom SVG icons from your theme.", "author": "Be API Technical team", "license": "GPL-2.0-or-later", diff --git a/readme.txt b/readme.txt index 9125819..3c5ef0a 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: block, icons, svg, gutenberg, editor Requires at least: 6.2 Tested up to: 6.8 Requires PHP: 8.1 -Stable tag: 1.1.2 +Stable tag: 1.1.1 License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -36,9 +36,6 @@ Yes. Register a collection with `type` set to `folder` and `source` pointing to == Changelog == -= 1.1.2 = -* Resolve missing `icon.collection` during `beapi/icon-block` migration via registry lookup and a generic fallback. - = 1.1.1 = * Fix deprecated warning for nullable string parameters in `CollectionItem`. * Align GitHub workflows with other blockparty repos and add release version consistency checks. diff --git a/src/block.json b/src/block.json index d447f27..ffd022b 100644 --- a/src/block.json +++ b/src/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "blockparty/icon", - "version": "1.1.2", + "version": "1.1.1", "title": "Icon", "category": "widgets", "description": "Easily add custom vector icon to your content.",