Skip to content

Commit 5b5158a

Browse files
committed
added query hook for query single content command
1 parent 1da943e commit 5b5158a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Darryldecode/Backend/Components/ContentBuilder/Commands/QueryContentCommand.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,27 @@ class QueryContentCommand extends Command implements SelfHandling {
2222
* @var null
2323
*/
2424
private $title;
25+
/**
26+
* @var null
27+
*/
28+
private $queryHook;
2529

2630
/**
2731
* @param null $id
2832
* @param null $slug
2933
* @param null $title
3034
* @param bool $disablePermissionChecking
35+
* @param null|callable $queryHook
3136
*/
32-
public function __construct($id = null, $slug = null, $title = null, $disablePermissionChecking = false)
37+
public function __construct($id = null, $slug = null, $title = null, $disablePermissionChecking = false, $queryHook = null)
3338
{
3439
parent::__construct();
3540
$this->id = $id;
3641
$this->slug = $slug;
3742
$this->title = $title;
3843
$this->args = func_get_args();
3944
$this->disablePermissionChecking = $disablePermissionChecking;
45+
$this->queryHook = $queryHook;
4046
}
4147

4248
/**
@@ -76,6 +82,14 @@ private function query($contentType, $content)
7682
'type'
7783
));
7884

85+
if( !is_null($this->queryHook) && (is_callable($this->queryHook)) )
86+
{
87+
if( $res = call_user_func($this->queryHook,$q) )
88+
{
89+
$q = $res;
90+
}
91+
}
92+
7993
if( !is_null($this->id) && ($this->id != '') )
8094
{
8195
return $q->find($this->id);

tests/ContentBuilder/functional/commands/QueryContentsCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testQueryByType()
6363
$result = $this->commandDispatcher->dispatchFromArray(
6464
'Darryldecode\Backend\Components\ContentBuilder\Commands\QueryContentsCommand',
6565
array(
66-
'type' => 'Blog'
66+
'type' => 'Blog',
6767
)
6868
);
6969

0 commit comments

Comments
 (0)