Create withComponent() filter for CmsObjects
This commit is contained in:
parent
67ba31b946
commit
9d4bc8eee6
|
|
@ -1,7 +1,7 @@
|
|||
<?php namespace Cms\Classes;
|
||||
|
||||
use Illuminate\Support\Collection as CollectionBase;
|
||||
use ApplicationException;
|
||||
use Illuminate\Support\Collection as CollectionBase;
|
||||
|
||||
/**
|
||||
* This class represents a collection of Cms Objects.
|
||||
|
|
@ -11,4 +11,24 @@ use ApplicationException;
|
|||
*/
|
||||
class CmsObjectCollection extends CollectionBase
|
||||
{
|
||||
/**
|
||||
* Returns objects that use the supplied component.
|
||||
* @param string|array $components
|
||||
* @return static
|
||||
*/
|
||||
public function withComponent($components)
|
||||
{
|
||||
return $this->filter(function($object) use ($components) {
|
||||
|
||||
$hasComponent = false;
|
||||
|
||||
foreach ((array) $components as $component) {
|
||||
if ($object->hasComponent($component)) {
|
||||
$hasComponent = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $hasComponent;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,18 @@ use ApplicationException;
|
|||
/**
|
||||
* This class provides helper methods to make the CmsObject behave like a Model
|
||||
*
|
||||
* Some examples:
|
||||
*
|
||||
* Page::find('blog/post');
|
||||
*
|
||||
* Page::all();
|
||||
*
|
||||
* Page::inEditTheme()->useCache()->all();
|
||||
*
|
||||
* Page::withComponent('blogPost')
|
||||
* ->sortBy('baseFileName')
|
||||
* ->lists('baseFileName', 'baseFileName');
|
||||
*
|
||||
* @package october\cms
|
||||
* @author Alexey Bobkov, Samuel Georges
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue