Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.4' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jul 30, 2018
2 parents 6178b4f + ee3f0cf commit e3b2d3e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## 1.0.4 - 2018.07.30
### Changed
* Code cleanup
* Updated README.md with native Craft examples

## 1.0.3 - 2018.03.02
### Changed
* Fixed deprecation errors from Craft CMS 3 RC13
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Allows you to eager load elements from auto-injected Entry elements on demand fr

Related: [Eager Beaver for Craft 2.6.x](https://github.com/nystudio107/eagerbeaver)

Learn More: [Speed up your Craft CMS Templates with Eager Loading](https://nystudio107.com/blog/speed-up-your-craft-cms-templates-with-eager-loading)
## Requirements

This plugin requires Craft CMS 3.0.0-RC1 or later.
This plugin requires Craft CMS 3.0.0 or later.

## Installation

Expand All @@ -34,6 +35,20 @@ Eager Beaver is a small plugin that allows you to eager load sub-elements like A

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.

## Do It Natively

Note that on Craft 3, you can do the exact same thing that the Eager Beaver plugin does by using `craft.app.elements.eagerLoadElements`:

```twig
{% do craft.app.elements.eagerLoadElements(
className(entry),
[entry],
['assetsField', 'categoriesField.assetField', 'matrixField.blockType:assetsField']
) %}
```

The first parameter is the class name of the element type we're eager loading elements into (in this case, an entry). The second parameter is an array of elements we're eager loading elements into (in this case, an array with just our entry in it). Finally, the third parameter is dot-notation of what elements we want to eager load. c.f.: [eagerLoadElements()](https://docs.craftcms.com/api/v3/craft-services-elements.html#public-methods)

## Configuring Eager Beaver

There's nothing to configure.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "nystudio107/craft-eagerbeaver",
"description": "Allows you to eager load elements from auto-injected Entry elements on demand from your templates.",
"type": "craft-plugin",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"eager",
"loading",
"eager loeading",
"eager loading",
"eager beaver"
],
"support": {
Expand All @@ -25,7 +25,7 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1"
"craftcms/cms": "^3.0.0"
},
"repositories": [
{
Expand Down
7 changes: 2 additions & 5 deletions src/EagerBeaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Eager Beaver plugin for Craft CMS 3.x
*
* Allows you to eager load elements from auto-injected Entry elements on demand from your templates.
* Allows you to eager load elements from auto-injected Entry elements on
* demand from your templates.
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2017 nystudio107
Expand Down Expand Up @@ -73,8 +74,4 @@ function (Event $event) {
__METHOD__
);
}

// Protected Methods
// =========================================================================

}
6 changes: 3 additions & 3 deletions src/services/EagerBeaverService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ class EagerBeaverService extends Component
public function eagerLoadElements($elements, $with)
{
// Bail if there aren't even any elements
if (!$elements || empty($elements)) {
if (empty($elements)) {
return;
}

if (!is_array($elements)) {
if (!\is_array($elements)) {
$elements = [$elements];
}
// We are assuming all of these elements are of the same type
/** @var Element $element */
$element = $elements[0];
$elementType = get_class($element);
$elementType = \get_class($element);
Craft::$app->elements->eagerLoadElements($elementType, $elements, $with);
}
}
2 changes: 1 addition & 1 deletion src/translations/en/eager-beaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
* @since 1.0.0
*/
return [
'Eager Beaver plugin loaded' => 'Eager Beaver plugin loaded',
'{name} plugin loaded' => '{name} plugin loaded'
];
12 changes: 8 additions & 4 deletions src/twigextensions/EagerBeaverTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Eager Beaver plugin for Craft CMS 3.x
*
* Allows you to eager load elements from auto-injected Entry elements on demand from your templates.
* Allows you to eager load elements from auto-injected Entry elements on
* demand from your templates.
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2017 nystudio107
Expand All @@ -12,7 +13,6 @@

use nystudio107\eagerbeaver\EagerBeaver;

use Craft;
use craft\base\ElementInterface;

/**
Expand Down Expand Up @@ -48,8 +48,12 @@ public function getFunctions()
/**
* Eager-loads additional elements onto a given set of elements.
*
* @param ElementInterface[] $elements The root element models that should be updated with the eager-loaded elements
* @param string|array $with Dot-delimited paths of the elements that should be eager-loaded into the root elements
* @param ElementInterface[] $elements The root element models that should
* be updated with the eager-loaded
* elements
* @param string|array $with Dot-delimited paths of the elements
* that should be eager-loaded into the
* root elements
*
* @return void
*/
Expand Down
12 changes: 8 additions & 4 deletions src/variables/EagerBeaverVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Eager Beaver plugin for Craft CMS 3.x
*
* Allows you to eager load elements from auto-injected Entry elements on demand from your templates.
* Allows you to eager load elements from auto-injected Entry elements on
* demand from your templates.
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2017 nystudio107
Expand All @@ -12,7 +13,6 @@

use nystudio107\eagerbeaver\EagerBeaver;

use Craft;
use craft\base\ElementInterface;

/**
Expand All @@ -32,8 +32,12 @@ class EagerBeaverVariable
/**
* Eager-loads additional elements onto a given set of elements.
*
* @param ElementInterface[] $elements The root element models that should be updated with the eager-loaded elements
* @param string|array $with Dot-delimited paths of the elements that should be eager-loaded into the root elements
* @param ElementInterface[] $elements The root element models that should
* be updated with the eager-loaded
* elements
* @param string|array $with Dot-delimited paths of the elements
* that should be eager-loaded into the
* root elements
*
* @return void
*/
Expand Down

0 comments on commit e3b2d3e

Please sign in to comment.