Skip to content

Commit e4518c4

Browse files
committed
blocks and layout fields support
1 parent c86eb7d commit e4518c4

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,6 @@ fields:
203203
theme: positive
204204
whenQuery: date && _status = 'listed'
205205
```
206+
207+
## Known issues
208+
- This plugin extends and replaces the default `Blocks` and `Layout` field types. This means that it is not compatible with other plugins that do the same.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rasteiner/k3-whenquery",
33
"description": "Conditionally show fields and sections. Better.",
44
"type": "kirby-plugin",
5-
"version": "0.2.2",
5+
"version": "0.3.0",
66
"license": "MIT",
77
"homepage": "https://getkirby.com/plugins/rasteiner/k3-whenquery",
88
"authors": [

index.php

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
1-
<?php
1+
<?php
2+
namespace rasteiner\whenquery;
23

3-
Kirby::plugin('rasteiner/whenquery', []);
4+
use Kirby\Cms\App as Kirby;
5+
use Kirby\Form\Field\BlocksField;
6+
use Kirby\Form\Field\LayoutField;
7+
8+
class QueryBlocksField extends BlocksField
9+
{
10+
protected string $whenQuery;
11+
12+
public function __construct($params)
13+
{
14+
parent::__construct($params);
15+
$this->setWhenQuery($params['whenQuery'] ?? null);
16+
}
17+
18+
public function setWhenQuery(?string $query)
19+
{
20+
$this->whenQuery = $query;
21+
}
22+
23+
public function whenQuery(): ?string
24+
{
25+
return $this->whenQuery;
26+
}
27+
28+
public function props(): array
29+
{
30+
return [
31+
'whenQuery' => $this->whenQuery(),
32+
] + parent::props();
33+
}
34+
35+
public function type(): string
36+
{
37+
return 'blocks';
38+
}
39+
}
40+
41+
class QueryLayoutField extends LayoutField
42+
{
43+
protected string $whenQuery;
44+
45+
public function __construct($props)
46+
{
47+
parent::__construct($props);
48+
$this->setWhenQuery($props['whenQuery'] ?? null);
49+
}
50+
51+
public function setWhenQuery(?string $query)
52+
{
53+
$this->whenQuery = $query;
54+
}
55+
56+
public function whenQuery(): ?string
57+
{
58+
return $this->whenQuery;
59+
}
60+
61+
public function props(): array
62+
{
63+
return [
64+
'whenQuery' => $this->whenQuery(),
65+
] + parent::props();
66+
}
67+
68+
public function type(): string
69+
{
70+
return 'layout';
71+
}
72+
}
73+
74+
Kirby::plugin('rasteiner/whenquery', [
75+
'fields' => [
76+
'blocks' => QueryBlocksField::class,
77+
'layout' => QueryLayoutField::class,
78+
],
79+
]);

0 commit comments

Comments
 (0)