Problem/Motivation
An Attachment display is not usable until its displays option names the display(s) it attaches to - creating the display alone leaves it attached to nothing. This saves without any tool error and passes View::validate() cleanly, since an attachment display with no target is not invalid Views config, just functionally useless.
Live-tested against the shipped agent with an explicit, unambiguous request ("add an attachment display that attaches before the page_1 display"): the agent created the attachment display and correctly set attachment_position: before, but never set displays at all. The resulting display was confirmed genuinely non-functional: ViewExecutable::attachDisplays() found nothing to attach to, and the target page never rendered the attachment alongside it.
Steps to reproduce
- Create an attachment display on a View with at least one other real display (e.g.
page_1) withai_agents_views:create_view_display. - Ask the tool what to set the attachment's
displaysoption to, by callingai_agents_views:update_view_pluginswithdisplay_idanddisplay_option: "displays"but noconfig.
Expected: the tool's "available config values" response lists the View's real other display IDs (e.g. page_1), so the agent knows what to set.
Actual (before this fix): both the "existing" and "available" values come back as an empty array ([]) - no hint that real display IDs are valid, or that the option expects a keyed map of display ID to display ID at all.
Root cause
ViewsAgentHelper::getViewDisplayOptionsConfigSuggestions() is a match() keyed by display-option name, with hand-picked example values for options like title, pager, style, row, access, exposed_form, and relationships - but had no case for 'displays', so it fell through to the default, empty array. Since displays is also never set on a freshly-created attachment display, getViewDisplayOptionsConfig()'s own "existing" value is empty too - so the tool told the agent both existing and available values were [], with nothing to go on.
This is the same class of gap as the earlier use_admin_theme discoverability defect, just on the "what value goes here" side rather than the "does this option exist at all" side.
Proposed resolution
Add a 'displays' case that returns the View's other real display IDs, keyed by themselves - exactly the shape the option expects:
'displays' => $this->getOtherDisplayIdsSuggestion($display), ... protected function getOtherDisplayIdsSuggestion(DisplayPluginInterface $display): array { $current_display_id = $display->display['id']; $other_display_ids = array_diff(array_keys($display->view->storage->get('display')), [$current_display_id]); return array_combine($other_display_ids, $other_display_ids); }
Also documents the full workflow in the system prompt: create the attachment display, set displays to the exact {"page_1":"page_1"} shape (confirming the real display ID first, since a view can have several page displays), set attachment_position, and add the attachment's own fields/filters/sorts like any other display.
Remaining tasks
- File this issue on drupal.org.
- Open an MR with the fix above.
Test coverage added locally
Regression test testDisplaysOptionSuggestsOtherDisplayIds() in tests/src/Kernel/Plugin/AiFunctionCall/UpdateViewPluginsTest.php confirms the tool now suggests the View's real other display ID (page_1) when asked what to set displays to on a fresh attachment display, then sets it and confirms the correct, real value round-trips through the saved config.
Full suite with this fix applied (isolated on its own branch): 15/15 kernel tests passing (126 assertions) in UpdateViewPluginsTest, no failures.
API changes
None to the tool's own context definitions. Adds one new protected method (getOtherDisplayIdsSuggestion()) to ViewsAgentHelper.
Issue fork ai_agents_views-3621957
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jibranComment #5
jibranCommitted and pushed to 1.0.x