Coffee
An Alfred/Spotlight-inspired quick navigation search box that allows users to rapidly navigate to any admin page or execute commands within Drupal using keyboard shortcuts and autocomplete search.
coffee
Install
composer require 'drupal/coffee:^2.0'
composer require 'drupal/coffee:8.x-1.4'
composer require 'drupal/coffee:8.x-1.2'
Overview
The Coffee module provides a powerful Alfred/Spotlight-like search interface for fast navigation within Drupal's administrative interface. It allows administrators and editors to quickly jump to any admin page, create content, or execute custom commands without having to navigate through complex menu structures.
When activated via the keyboard shortcut (Alt+D) or toolbar button, a sleek search dialog appears where users can type part of a page title or path. The module instantly filters and displays matching results from configured menus, enabling users to navigate with just a few keystrokes. For example, typing 'ap' and pressing Enter will navigate directly to the Appearance admin page.
Coffee is highly extensible through the hook_coffee_commands() API, allowing other modules to add custom commands and search results. The module comes with built-in commands like :front to go to the front page and :add for quick content creation of any content type.
Features
- Quick navigation search box activated via Alt+D keyboard shortcut or toolbar button
- Real-time autocomplete filtering across multiple menus including admin menu, account menu, and any other configured menus
- Built-in :front command to quickly navigate to the front page
- Built-in :add command for rapid content creation with support for all content types (e.g., :add Article)
- Extensible via hook_coffee_commands() allowing modules to add custom commands and navigation items
- Configurable number of search results (1-50, default 7)
- Keyboard navigation support with arrow keys to browse results and Enter to select
- Open results in new window with Ctrl+Enter (Windows) or Cmd+Enter (macOS)
- Seamless toolbar integration with a 'Go to' button for mouse users
- Access control with separate permissions for using and administering Coffee
- Automatic access checking ensures users only see menu items they have permission to access
- Support for local tasks providing additional navigation to translate pages when Config Translation is enabled
- Includes Configuration Translation pages in search results when available
- Clean, modal-style dark UI with smooth transitions
- CSRF token handling for secure navigation
Use Cases
Quick Navigation to Admin Pages
As a site administrator managing a complex Drupal site, you need to frequently access various admin pages like Content, Structure, People, or Reports. Instead of clicking through multiple menu levels, simply press Alt+D, type a few characters (e.g., 'cont' for Content, 'peo' for People, or 'rep' for Reports), and press Enter to navigate instantly.
Rapid Content Creation
Content editors who frequently create new content can use the :add command to quickly access the node creation form. Press Alt+D, type ':add Article' or ':add Page', and press Enter to go directly to the content creation form for that type. This bypasses the Content > Add content menu navigation entirely.
Accessing the Front Page Quickly
When working in the admin area and needing to preview the site's front page, use the :front command. Press Alt+D, type ':front', and press Enter to navigate to the site's front page immediately.
Custom Module Integration
Developers can extend Coffee by implementing hook_coffee_commands() in their modules. For example, a custom dashboard module could add commands like ':dashboard' to jump to a custom admin dashboard, or ':reports' to access custom reporting pages. This makes module-specific functionality easily accessible through Coffee.
Multi-Menu Search Setup
For sites using multiple menus (e.g., admin, main navigation, footer), administrators can configure Coffee to search across all of them. This allows editors to find any linked page on the site quickly, not just admin pages. Enable additional menus at /admin/config/user-interface/coffee.
Opening Admin Pages in New Tabs
When you need to open multiple admin pages simultaneously (e.g., comparing configurations or editing content while referencing another page), use Coffee with Ctrl+Enter (Windows) or Cmd+Enter (Mac) to open results in new browser tabs without leaving your current page.
Integrating with Devel Module
When the Devel module is installed, its menu items become searchable through Coffee. Type 'clear' to find and navigate to the cache clearing page (devel/cache/clear) or 'phpinfo' to access the PHP info page, streamlining developer workflows.
Tips
- Use short, memorable search terms - Coffee matches against page titles, paths, and commands, so typing just 2-3 characters is often enough
- Prefix commands with a colon (:) for built-in commands like :front and :add
- Configure fewer menus for faster, more focused results when you primarily need admin navigation
- Increase max_results in configuration if you frequently need to see more options before making a selection
- Combine Coffee with the Devel module for quick access to developer tools and cache clearing
- Remember that Coffee respects access permissions - users will only see menu items they have permission to access
- Use the escape key to quickly close the Coffee dialog if you change your mind
Technical Details
Admin Pages 1
/admin/config/user-interface/coffee
Configure which menus Coffee should search through and how many results to display in the autocomplete dropdown.
Permissions 2
Hooks 1
hook_coffee_commands
Extend the Coffee functionality with custom commands and navigation items. This hook allows modules to add their own searchable items to the Coffee interface, enabling quick navigation to custom pages or execution of module-specific commands.
Troubleshooting 5
Ensure the user has the 'Access Coffee' permission. Check that the coffee library is being loaded by inspecting the page source for coffee.js. Clear all caches and try again.
Verify that at least one menu is selected in the Coffee configuration at /admin/config/user-interface/coffee. Ensure the selected menus contain items and the user has access permissions to those menu items.
The toolbar button only appears for users with both 'Access Coffee' and 'Access toolbar' permissions. Install and enable the Toolbar module if not already active, and ensure proper permissions are granted.
Ensure your implementation is in a .coffee.inc file (as defined by hook_hook_info()) or in the main .module file. Clear all caches after adding new commands. Verify the hook returns an array with 'value', 'label', and 'command' keys for each item.
In some browsers (particularly Opera and Internet Explorer), use Alt+Shift+D or Alt+Ctrl+D respectively. You can also click the Coffee icon in the toolbar if keyboard shortcuts are problematic.
Security Notes 4
- Coffee automatically applies access checks to all menu items, ensuring users only see navigation options they have permission to access
- CSRF tokens are properly handled for routes that require them, preventing potential security vulnerabilities
- The module creates separate permissions for using (access coffee) and administering (administer coffee) the feature, following Drupal's principle of least privilege
- All menu item titles are properly escaped using Html::escape() to prevent XSS vulnerabilities