Skip to main content

Droost: Views Compose

droost_views_compose Write (gated)

Module: Droost Views

The listings composer: an intent spec (bundle, view mode, page/block, style, sorts, filters) becomes a complete, schema-valid view — exposed filters generated per plugin family, published+bundle scoping automatic, block.filters for featured rows. This site's /tools reference is one call to it. Discover fields with droost_views_handlers first; dry_run rehearses.

Example call
{
    "tool": "droost_views_compose",
    "arguments": {
        "id": "tools",
        "label": "Tool reference",
        "bundle": "tool",
        "view_mode": "teaser",
        "page": {
            "path": "/tools",
            "title": "Tool reference"
        },
        "style": {
            "type": "grid",
            "columns": 3
        },
        "sorts": [
            {
                "field": "title",
                "order": "asc"
            }
        ],
        "filters": [
            {
                "field": "field_tool_module",
                "exposed": true,
                "label": "Module",
                "identifier": "module"
            },
            {
                "field": "title",
                "op": "contains",
                "exposed": true,
                "label": "Search",
                "identifier": "search"
            }
        ],
        "replace": true,
        "dry_run": true
    }
}
Example response — captured live on this site
{
    "success": true,
    "message": "Dry run: view \"tools\" is valid (4 filter(s), 2 exposed; 1 sort(s)). Call again with dry_run=false to save.",
    "data": {
        "id": "tools",
        "base_table": "node_field_data",
        "displays": [
            "default",
            "page_1"
        ],
        "path": "/tools",
        "canvas_component": null,
        "filters": [
            "field_tool_module",
            "title",
            "status",
            "type"
        ],
        "auto_filters": [
            "status",
            "type"
        ],
        "exposed_filters": 2,
        "block_filters": null,
        "sorts": [
            "title"
        ],
        "view_mode": "teaser",
        "view": {
            "id": "tools",
            "label": "Tool reference",
            "module": "views",
            "description": "",
            "tag": "",
            "base_table": "node_field_data",
            "base_field": "nid",
            "status": true,
            "display": {
                "default": {
                    "id": "default",
                    "display_title": "Default",
                    "display_plugin": "default",
                    "position": 0,
                    "display_options": {
                        "title": "Tool reference",
                        "access": {
                            "type": "perm",
                  
… (truncated — run it yourself for the rest)

Composes a complete listing view of one entity bundle from an intent spec: rows render entities in a view mode (pair with droost_display_compose for SDC teasers), with a page display (path) and/or block display (Canvas-placeable), grid/list style, sorts, and filters — exposed filters get full expose config generated per filter plugin. Published + bundle filters are added automatically. Use droost_views_handlers first to see filterable/sortable fields and their ops. Validates everything (all-or-nothing) via the Views validator before saving. Set dry_run=true to preview; replace=true to overwrite an existing view. Destructive (config write): requires droost.settings.allow_destructive.

Input schema (JSON Schema)
{
    "type": "object",
    "properties": {
        "id": {
            "type": "string",
            "description": "View machine name (lowercase letters, numbers, underscores), e.g. \"vehicles\"."
        },
        "label": {
            "type": "string",
            "description": "Human-readable view label, e.g. \"Vehicle inventory\"."
        },
        "entity_type": {
            "type": "string",
            "description": "Entity type id (default \"node\")."
        },
        "bundle": {
            "type": "string",
            "description": "Bundle machine name the view lists, e.g. \"vehicle\"."
        },
        "view_mode": {
            "type": "string",
            "description": "View mode rows render in (default \"teaser\"). Compose it from SDCs with droost_display_compose."
        },
        "description": {
            "type": "string",
            "description": "Administrative description."
        },
        "page": {
            "type": "object",
            "description": "Add a page display. {path: \"/vehicles\", title?: \"Inventory\"}.",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "The page path, e.g. \"/vehicles\"."
                },
                "title": {
                    "type": "string",
                    "description": "Page title (defaults to the view label)."
                },
                "id": {
                    "type": "string",
                    "description": "Display machine name (default \"page_1\"). Set it when replacing a view whose display ids must not change."
                }
            },
            "required": [
                "path"
            ]
        },
        "block": {
            "type": "object",
            "description": "Add a block display (Canvas-placeable). {label?: \"Featured vehicles\", items_per_page?: 4}.",
            "properties": {
                "label": {
                    "type": "string",
                    "description": "Block admin label (defaults to the view label)."
                },
                "items_per_page": {
                    "type": "integer",
                    "description": "Fixed item count for the block (no pager)."
                },
                "id": {
                    "type": "string",
                    "description": "Display machine name (default \"block_1\"). The Canvas component id embeds it — keep it stable when replacing a view already placed in Canvas."
                },
                "filters": {
                    "type": "array",
                    "description": "Block-only filters REPLACING the shared ones (published + bundle scoping re-added automatically). Same shape as top-level filters but never exposed. The featured-row pattern: [{\"field\": \"field_featured\", \"op\": \"equals\", \"value\": 1}].",
                    "items": {
                        "type": "object",
                        "properties": {
                            "field": {
                                "type": "string",
                                "description": "Entity field name."
                            },
                            "op": {
                                "type": "string",
                                "description": "Intent op (see droost_views_handlers filter_ops)."
                            },
                            "value": {
                                "description": "Filter value."
                            }
                        },
                        "required": [
                            "field"
                        ]
                    }
                }
            }
        },
        "style": {
            "type": "object",
            "description": "Row layout: {type: \"grid\"|\"html_list\"|\"unformatted\", columns?: 3}. Default grid, 3 columns.",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "grid",
                        "html_list",
                        "unformatted"
                    ],
                    "description": "Style plugin (default \"grid\")."
                },
                "columns": {
                    "type": "integer",
                    "description": "Grid columns (default 3; grid only)."
                }
            }
        },
        "items_per_page": {
            "type": "integer",
            "description": "Items per page with a mini pager (default 12)."
        },
        "sorts": {
            "type": "array",
            "description": "Sort order: [{field: \"field_price\", order: \"asc\"|\"desc\"}]. Fields from droost_views_handlers (sortable: true).",
            "items": {
                "type": "object",
                "properties": {
                    "field": {
                        "type": "string",
                        "description": "Entity field name."
                    },
                    "order": {
                        "type": "string",
                        "enum": [
                            "asc",
                            "desc"
                        ],
                        "description": "Direction (default \"asc\")."
                    }
                },
                "required": [
                    "field"
                ]
            }
        },
        "filters": {
            "type": "array",
            "description": "Filters: [{field, op?, value?, exposed?, label?, identifier?}]. op per field from droost_views_handlers filter_ops (equals, contains, in, min, max, between, …). exposed=true renders a visitor-facing filter (label = its form label, identifier = its query parameter); op defaults per plugin when exposed. value for \"between\" is [min, max]; for \"in\" a list. Published + bundle filters are automatic — only list them to override.",
            "items": {
                "type": "object",
                "properties": {
                    "field": {
                        "type": "string",
                        "description": "Entity field name."
                    },
                    "op": {
                        "type": "string",
                        "description": "Intent op (see droost_views_handlers filter_ops)."
                    },
                    "value": {
                        "description": "Filter value: scalar, list (for \"in\"), or [min, max] (for \"between\"). Omit for exposed filters with no default."
                    },
                    "exposed": {
                        "type": "boolean",
                        "description": "Expose to visitors (default false)."
                    },
                    "label": {
                        "type": "string",
                        "description": "Exposed form label."
                    },
                    "identifier": {
                        "type": "string",
                        "description": "Exposed query parameter name (default: the field name)."
                    }
                },
                "required": [
                    "field"
                ]
            }
        },
        "replace": {
            "type": "boolean",
            "description": "Overwrite an existing view with this id, preserving its UUID (default false)."
        },
        "dry_run": {
            "type": "boolean",
            "description": "Validate and return the would-be view config without saving (default false)."
        }
    },
    "required": [
        "id",
        "label",
        "bundle"
    ]
}