├── resources ├── screenshots │ └── beaver.png └── icon.svg ├── .gitignore ├── CHANGELOG.md ├── translations └── en.php ├── composer.json ├── .craftplugin ├── releases.json ├── variables └── EagerBeaverVariable.php ├── LICENSE.txt ├── twigextensions └── EagerBeaverTwigExtension.php ├── services └── EagerBeaverService.php ├── EagerBeaverPlugin.php └── README.md /resources/screenshots/beaver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nystudio107/eagerbeaver/master/resources/screenshots/beaver.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # BUILD FILES 2 | /bower_components/* 3 | /node_modules/* 4 | /build/* 5 | 6 | # MISC FILES 7 | .cache 8 | .DS_Store 9 | .idea 10 | .project 11 | .settings 12 | *.esproj 13 | *.sublime-workspace 14 | *.sublime-project 15 | *.tmproj 16 | *.tmproject 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Eager Beaver Changelog 2 | 3 | ## 1.0.1 -- 2017-09-30 4 | ### Added 5 | * Added a TwigExtension to allow for the less verbose `do eagerLoadElements()` syntax 6 | 7 | ### Changed 8 | * Updated README.md 9 | 10 | ## 1.0.0 -- 2017-09-27 11 | ### Added 12 | * Initial release 13 | 14 | Brought to you by [nystudio107](https://nystudio107.com/) 15 | -------------------------------------------------------------------------------- /translations/en.php: -------------------------------------------------------------------------------- 1 | 'To this', 16 | ); 17 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nystudio107/eagerbeaver", 3 | "description": "Allows you to eager load elements from auto-injected Entry elements on demand from your templates.", 4 | "type": "craft-plugin", 5 | "authors": [ 6 | { 7 | "name": "nystudio107", 8 | "homepage": "https://nystudio107.com/" 9 | } 10 | ], 11 | "require": { 12 | "composer/installers": "~1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.craftplugin: -------------------------------------------------------------------------------- 1 | {"pluginName":"Eager Beaver","pluginDescription":"Allows you to eager load elements from auto-injected elements on demand from your templates.","pluginVersion":"1.0.0","pluginAuthorName":"nystudio107","pluginAuthorUrl":"https://nystudio107.com/","pluginAuthorGithub":"nystudio107","codeComments":"","pluginComponents":["twigextensions","services","variables"],"controllerName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","widgetName":"","apiVersion":"api_version_2_5"} -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "version": "1.0.1", 4 | "downloadUrl": "https://github.com/nystudio107/eagerbeaver/archive/master.zip", 5 | "date": "2017-09-30T20:07:51.630Z", 6 | "notes": [ 7 | "[Added] Added a TwigExtension to allow for the less verbose `do eagerLoadElements()` syntax", 8 | "[Improved] Updated README.md" 9 | ] 10 | }, 11 | { 12 | "version": "1.0.0", 13 | "downloadUrl": "https://github.com/nystudio107/eagerbeaver/archive/master.zip", 14 | "date": "2017-09-27T20:07:51.630Z", 15 | "notes": [ 16 | "[Added] Initial release" 17 | ] 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /variables/EagerBeaverVariable.php: -------------------------------------------------------------------------------- 1 | eagerBeaver->eagerLoadElements($elements, $with); 29 | } 30 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2017 nystudio107 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /twigextensions/EagerBeaverTwigExtension.php: -------------------------------------------------------------------------------- 1 | new \Twig_Function_Method($this, 'eagerLoadElements'), 36 | ]; 37 | } 38 | 39 | /** 40 | * Eager-loads additional elements onto a given set of elements. 41 | * 42 | * @param BaseElementModel[] $elements The root element models that should be updated with the eager-loaded elements 43 | * @param string|array $with Dot-delimited paths of the elements that should be eager-loaded into the root elements 44 | * 45 | * @return void 46 | */ 47 | public function eagerLoadElements($elements, $with) 48 | { 49 | craft()->eagerBeaver->eagerLoadElements($elements, $with); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /services/EagerBeaverService.php: -------------------------------------------------------------------------------- 1 | elements->getElementType($element->elementType); 42 | craft()->elements->eagerLoadElements($elementType, $elements, $with); 43 | } 44 | } -------------------------------------------------------------------------------- /EagerBeaverPlugin.php: -------------------------------------------------------------------------------- 1 | Plugins 25 | 5. The plugin folder should be named `eagerbeaver` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads. 26 | 27 | Eager Beaver works on Craft 2.6.x. 28 | 29 | ## Eager Beaver Overview 30 | 31 | Craft's [Eager-Loading Elements](https://craftcms.com/docs/templating/eager-loading-elements) allows you to nicely optimize your templates by telling Craft to load everything you need in one big query. 32 | 33 | The only rub is that you can't specify this eager loading behavior for `entry`, `category`, or `product` elements that are auto-injected into your template. 34 | 35 | Eager Beaver is a small plugin that allows you to eager load sub-elements like Assets, Categories, Users, etc. to these auto-injected elements. 36 | 37 | This is especially useful if you have pages that use Matrix block "content builders", and thus will typically result in loading a number of relations like Assets contained in Matrix blocks to render a page. 38 | 39 | ## Configuring Eager Beaver 40 | 41 | There's nothing to configure. 42 | 43 | ## Using Eager Beaver 44 | 45 | To use Eager Beaver, simply do something like: 46 | 47 | ``` 48 | {% do eagerLoadElements(entry, [ 49 | 'author.userPicture', 50 | 'blogCategory', 51 | 'blogImage', 52 | 'blogContent.image:image' 53 | ]) %} 54 | ``` 55 | 56 | Or you can use the more verbose syntax to do the same thing: 57 | 58 | ``` 59 | {% do craft.eagerBeaver.eagerLoadElements(entry, [ 60 | 'author.userPicture', 61 | 'blogCategory', 62 | 'blogImage', 63 | 'blogContent', 64 | 'blogContent.image:image' 65 | ]) %} 66 | ``` 67 | 68 | The first parameter is the Element or array of Elements that you want to eager-load sub-elements into, such as an `entry`. If you pass in an array of Elements, they must all be the same type. 69 | 70 | The second parameter is the same `with:` that you use for [Eager-Loading Elements](https://craftcms.com/docs/templating/eager-loading-elements), and uses the exact same syntax. 71 | 72 | In the above example: 73 | - `author` is a `User` that has an Assets field named `userPicture` added to it. 74 | - `blogCategory` is a Category field 75 | - `blogImage` is an Asset field 76 | - `blogContent` is a Matrix field that has an Assets field named `image` added to the block type `image` 77 | 78 | ## Eager Beaver Roadmap 79 | 80 | Some things to do, and ideas for potential features: 81 | 82 | * Release it 83 | 84 | Brought to you by [nystudio107](https://nystudio107.com/) 85 | -------------------------------------------------------------------------------- /resources/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 11 | 12 | 15 | 17 | 19 | 20 | 22 | 23 | 28 | 29 | 31 | 33 | 41 | 43 | 46 | 50 | 60 | 62 | 67 | 70 | 71 | 72 | 73 | 74 | 76 | 78 | 81 | 83 | 85 | 87 | 91 | 95 | 99 | 101 | 103 | 112 | 114 | 117 | 120 | 124 | 133 | 135 | 140 | 145 | 148 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | --------------------------------------------------------------------------------