|
| 1 | +# Sidworks DevTools for Shopware 6 |
| 2 | + |
| 3 | +Never hunt for a Twig file again. Sidworks DevTools reveals the exact template and block behind every Shopware 6 element and lets you jump straight into your IDE with a single click. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +### Shopware Plugin |
| 8 | +- **Smart Template Tracking**: Automatically tracks every Twig block with detailed metadata (template name, file path, line number, parent template) |
| 9 | +- **HTML Markers**: Injects lightweight HTML comments (`<!-- SWDT:ID -->`) to map elements to their source templates |
| 10 | +- **Intelligent Line Detection API**: Backend endpoint that searches template files to find the exact line of your selected element (not just the block start) |
| 11 | +- **Security First**: Only active in debug mode (`APP_ENV=dev`) with configurable on/off switch |
| 12 | +- **Zero Production Impact**: Completely disabled in production environments |
| 13 | + |
| 14 | +### Chrome Extension |
| 15 | +- **DevTools Sidebar Integration**: Adds a "Shopware" panel in Chrome's Elements sidebar |
| 16 | +- **Instant Template Info**: Select any element to see its template, block name, file path, and inheritance chain |
| 17 | +- **Smart IDE Integration**: One-click to open templates at the exact line in PHPStorm or VSCode |
| 18 | +- **Intelligent Line Search**: Automatically finds the precise element line by searching for classes, IDs, and tags |
| 19 | +- **Multi-Editor Support**: Works with PHPStorm and VSCode |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +- Shopware 6.6.x |
| 24 | +- PHP 8.1 or higher |
| 25 | +- Chrome or Edge browser (for extension) |
| 26 | + |
| 27 | +## Installation |
| 28 | + |
| 29 | +### Plugin Installation |
| 30 | + |
| 31 | +#### Via Composer (Recommended) |
| 32 | + |
| 33 | +```bash |
| 34 | +composer require sidworks/sw-plugin-devtools --dev |
| 35 | +bin/console plugin:refresh |
| 36 | +bin/console plugin:install --activate SidworksDevTools |
| 37 | +bin/console cache:clear |
| 38 | +``` |
| 39 | + |
| 40 | +#### Manual Installation |
| 41 | + |
| 42 | +1. Clone or download this repository to `custom/plugins/SidworksDevTools` |
| 43 | +2. Run the following commands: |
| 44 | + |
| 45 | +```bash |
| 46 | +bin/console plugin:refresh |
| 47 | +bin/console plugin:install --activate SidworksDevTools |
| 48 | +bin/console cache:clear |
| 49 | +``` |
| 50 | + |
| 51 | +### Chrome Extension Installation |
| 52 | + |
| 53 | +1. Open Chrome and navigate to `chrome://extensions/` |
| 54 | +2. Enable **Developer mode** (toggle in top right) |
| 55 | +3. Click **Load unpacked** |
| 56 | +4. Select the `chrome-extension/` directory from this repository |
| 57 | +5. The extension icon will appear in your toolbar |
| 58 | + |
| 59 | +See [chrome-extension/README.md](chrome-extension/README.md) for detailed extension documentation. |
| 60 | + |
| 61 | +## Configuration |
| 62 | + |
| 63 | +### Plugin Configuration |
| 64 | + |
| 65 | +1. Ensure Shopware is running in debug mode: set `APP_ENV=dev` in your `.env` file |
| 66 | +2. (Optional) Navigate to **Settings** → **System** → **Plugins** in Shopware admin |
| 67 | +3. Find **Sidworks DevTools** and click **Configuration** to enable/disable |
| 68 | + |
| 69 | +### Extension Configuration |
| 70 | + |
| 71 | +1. Click the extension icon and select **Options** |
| 72 | +2. Set your **Project Path** (e.g., `/Users/yourname/Projects/shopware`) |
| 73 | +3. Choose your preferred **Editor** (PHPStorm or VSCode) |
| 74 | +4. Enable/disable **IDE Integration** |
| 75 | + |
| 76 | +The project path should be the absolute path to your Shopware root directory. |
| 77 | + |
| 78 | +**Tip for Docker/DDEV users**: Add the `PROJECT_PATH` environment variable to your `docker-compose.yml` or `.ddev/config.yaml`: |
| 79 | + |
| 80 | +```yaml |
| 81 | +web_environment: |
| 82 | + - PROJECT_PATH=/Users/yourname/Development/your-shopware-project |
| 83 | +``` |
| 84 | +
|
| 85 | +The plugin will automatically inject this path into the page, so you don't need to manually configure it in the extension options. |
| 86 | +
|
| 87 | +## Usage |
| 88 | +
|
| 89 | +### Basic Workflow |
| 90 | +
|
| 91 | +1. **Enable debug mode** in Shopware (`.env`: `APP_ENV=dev`) |
| 92 | +2. **Install both** the plugin and Chrome extension |
| 93 | +3. **Visit your storefront** in Chrome |
| 94 | +4. **Open DevTools** (F12 or right-click → Inspect) |
| 95 | +5. **Select any element** in the Elements panel |
| 96 | +6. **View template info** in the "Shopware" sidebar on the right |
| 97 | +7. **Click the IDE link** to jump directly to the template file at the exact line |
| 98 | + |
| 99 | +### What You'll See |
| 100 | + |
| 101 | +When you inspect an element, the sidebar shows: |
| 102 | + |
| 103 | +- **Template Type**: Page, Component, or Utility |
| 104 | +- **Block Name**: The Twig block that rendered this element |
| 105 | +- **Template Path**: Full Shopware namespace path (e.g., `@Storefront/storefront/page/product-detail/index.html.twig`) |
| 106 | +- **Parent Template**: The template this one extends (inheritance chain) |
| 107 | +- **File Path**: Relative filesystem path |
| 108 | +- **IDE Link**: Click to open in PHPStorm/VSCode at the exact element line |
| 109 | +- **Element Info**: Tag name, ID, and classes |
| 110 | + |
| 111 | +### Smart Line Detection |
| 112 | + |
| 113 | +The extension doesn't just open templates at the block start—it searches for the exact line: |
| 114 | + |
| 115 | +1. **Exact ID match**: `id="product-detail-123"` → finds exact match |
| 116 | +2. **Partial ID match**: `id="product-{{ product.id }}"` → matches static prefix |
| 117 | +3. **Multi-class match**: `class="btn btn-primary"` → tries all combinations |
| 118 | +4. **Parent context**: Uses parent element classes to disambiguate similar elements |
| 119 | +5. **Dynamic class prefix**: `class="card-{{ type }}"` → matches `card-` prefix |
| 120 | +6. **Tag fallback**: Falls back to tag name (`<div>`, `<img>`) if needed |
| 121 | + |
| 122 | +### Example Output |
| 123 | + |
| 124 | +``` |
| 125 | +📄 Page Template: index.html.twig |
| 126 | + |
| 127 | +🚀 Open in PHPStorm |
| 128 | + └─ Open file at line 42 |
| 129 | + └─ ✓ Found element at line 42 (matched: product-detail-content) |
| 130 | + |
| 131 | +📦 Block Name: page_product_detail |
| 132 | + |
| 133 | +📂 Full Path: @Storefront/storefront/page/product-detail/index.html.twig |
| 134 | + |
| 135 | +⬆️ Extends: @Storefront/storefront/base.html.twig |
| 136 | + |
| 137 | +💻 File Path: vendor/shopware/storefront/Resources/views/storefront/page/product-detail/index.html.twig |
| 138 | + |
| 139 | +🏷️ Element: DIV#product-123.product-detail-content |
| 140 | +🎨 Classes: product-detail-content container |
| 141 | +``` |
| 142 | +
|
| 143 | +## How It Works |
| 144 | +
|
| 145 | +### Backend (Plugin) |
| 146 | +
|
| 147 | +1. **TemplateDebugNodeVisitor**: Twig compiler visitor that wraps every block with tracking functions |
| 148 | +2. **TemplateDebugExtension**: Twig extension providing `swdt_track_block()`, `swdt_start_marker()`, and `swdt_end_marker()` |
| 149 | +3. **TemplateRegistry**: In-memory registry collecting all template metadata during page render |
| 150 | +4. **ResponseSubscriber**: Injects collected data into HTML response as JSON and wraps elements with `data-swdt` attributes |
| 151 | +5. **TemplateSearchController**: API endpoint (`/_action/sidworks-devtools/find-line`) that searches template files to find exact element lines |
| 152 | +
|
| 153 | +### Frontend (Extension) |
| 154 | +
|
| 155 | +1. **content.js**: Content script that detects DevTools data on page |
| 156 | +2. **background.js**: Service worker managing extension state |
| 157 | +3. **devtools-init.js**: Creates the "Shopware" sidebar panel |
| 158 | +4. **inspector.js**: Sidebar logic that reads element data and communicates with the page |
| 159 | +5. **Smart search**: Sends element classes/ID/tag to backend API to find exact line in template file |
| 160 | +
|
| 161 | +## Security |
| 162 | +
|
| 163 | +- **Debug Mode Only**: Plugin is completely disabled when `APP_ENV=prod` |
| 164 | +- **Configurable**: Can be disabled even in debug mode via plugin settings |
| 165 | +- **Input Validation**: API endpoint validates all inputs (class names, IDs, file paths) |
| 166 | +- **Path Traversal Protection**: Only allows reading `.twig` files within project directory |
| 167 | +- **No Production Data**: No overhead or data collection in production |
| 168 | +
|
| 169 | +## Browser Compatibility |
| 170 | +
|
| 171 | +The Chrome extension works with: |
| 172 | +- Google Chrome (Manifest V3) |
| 173 | +- Microsoft Edge (Chromium-based) |
| 174 | +- Brave |
| 175 | +- Other Chromium-based browsers |
| 176 | +
|
| 177 | +## License |
| 178 | +
|
| 179 | +MIT License - See [LICENSE](LICENSE.md) file for details |
| 180 | +
|
| 181 | +## Author |
| 182 | +
|
| 183 | +**Sidworks** |
| 184 | +Website: [www.sidworks.nl](https://www.sidworks.nl) |
| 185 | +
|
| 186 | +## Contributing |
| 187 | +
|
| 188 | +Contributions are welcome! Please feel free to submit issues or pull requests. |
| 189 | +
|
| 190 | +**Important**: This project consists of two components that work together: |
| 191 | +- **Shopware Plugin** (this directory) |
| 192 | +- **Chrome Extension** (`chrome-extension/` directory) |
| 193 | +
|
| 194 | +When updating the plugin, ensure you also update the extension if the changes affect the data format or API. Similarly, when updating the extension, verify compatibility with the plugin. Both components should be kept in sync. |
| 195 | +
|
| 196 | +## Support |
| 197 | +
|
| 198 | +For issues and questions: |
| 199 | +- Create an issue on GitHub |
0 commit comments