| @@ -8,10 +8,12 @@ | ||
| 8 | 8 | * Lists the types eligible for the graph (`slug`, `label`, `icon`, |
| 9 | 9 | * `count`, `taxonomies`). |
| 10 | 10 | * |
| 11 | 11 | * GET /nodes?types=post,page,... |
| 12 | - * Returns the full `{ nodes, edges, stats }` tuple. Cached server- | |
| 13 | - * side, see graph-builder.php. | |
| 12 | + * Returns the full `{ nodes, edges, groups, stats }` tuple. Cached | |
| 13 | + * server-side, see graph-builder.php. `types` omitted means every | |
| 14 | + * registered type; `types=` (present but empty) means none — the | |
| 15 | + * shell sends the latter when every toolbar chip is off. | |
| 14 | 16 | * |
| 15 | 17 | * GET /post/<id> |
| 16 | 18 | * Returns the side-panel detail bundle for one post: |
| 17 | 19 | * { post: {...}, author, contributors, comments, categories, |
| @@ -51,12 +53,17 @@ | ||
| 51 | 53 | 'methods' => WP_REST_Server::READABLE, |
| 52 | 54 | 'callback' => 'openstation_content_graph_rest_nodes', |
| 53 | 55 | 'permission_callback' => 'openstation_content_graph_rest_permission', |
| 54 | 56 | 'args' => array( |
| 57 | + // Deliberately no `default`: the dispatcher copies a | |
| 58 | + // registered default into the request before the | |
| 59 | + // callback runs, and `WP_REST_Request::has_param()` | |
| 60 | + // sees it, so a default here would make an omitted | |
| 61 | + // parameter indistinguishable from an explicitly empty | |
| 62 | + // one — and the callback tells those two apart. | |
| 55 | 63 | 'types' => array( |
| 56 | - 'description' => 'Comma-separated list of post type slugs to include.', | |
| 64 | + 'description' => 'Comma-separated list of post type slugs to include. Omit for every registered type; pass an empty value for none.', | |
| 57 | 65 | 'type' => 'string', |
| 58 | - 'default' => '', | |
| 59 | 66 | ), |
| 60 | 67 | ), |
| 61 | 68 | ) |
| 62 | 69 | ); |
| @@ -113,16 +120,21 @@ | ||
| 113 | 120 | |
| 114 | 121 | /** |
| 115 | 122 | * GET /nodes |
| 116 | 123 | * |
| 124 | + * An omitted `types` parameter selects every registered type; a | |
| 125 | + * present-but-empty one selects none. The route registers no default | |
| 126 | + * for the parameter so the two stay distinguishable through a real | |
| 127 | + * dispatch (see the route registration above). | |
| 128 | + * | |
| 117 | 129 | * @param WP_REST_Request $request |
| 118 | 130 | * @return WP_REST_Response |
| 119 | 131 | */ |
| 120 | 132 | function openstation_content_graph_rest_nodes( WP_REST_Request $request ) { |
| 121 | - $raw = (string) $request->get_param( 'types' ); | |
| 122 | - $types = '' === $raw | |
| 123 | - ? wp_list_pluck( openstation_content_graph_post_types(), 'slug' ) | |
| 124 | - : array_map( 'trim', explode( ',', $raw ) ); | |
| 133 | + $raw = $request->get_param( 'types' ); | |
| 134 | + $types = $request->has_param( 'types' ) | |
| 135 | + ? array_map( 'trim', explode( ',', (string) $raw ) ) | |
| 136 | + : wp_list_pluck( openstation_content_graph_post_types(), 'slug' ); | |
| 125 | 137 | $payload = openstation_content_graph_build( (array) $types ); |
| 126 | 138 | return rest_ensure_response( openstation_content_graph_filter_payload_for_user( $payload ) ); |
| 127 | 139 | } |
| 128 | 140 | |