Skip to content

Commit ec7513d

Browse files
committed
✨ Stats Section, Color Field, Props-based inline make, added missing @methods declarations
🐛 properties[] got set twice ✅ added some tests for Ink
1 parent ade7dfc commit ec7513d

File tree

27 files changed

+739
-326
lines changed

27 files changed

+739
-326
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ You will need to add two traits to your PageModel.
213213
Without defining a YAML blueprint for the `article` template Kirby would have an empty blueprint definition. But with the attributes defined in the PageModel Kirby will know what fields we want to have in the blueprint (registered by the *autoloader helper*).
214214

215215
**site/plugins/example/models/ArticlePage.php**
216+
216217
```php
217218
<?php
218219
@@ -259,7 +260,7 @@ Most likely you will want a more complex blueprint definition than just fields a
259260

260261
You can find all available PHP attributes in the [classes/Blueprints/Attributes folder](https://github.com/bnomei/kirby-blueprints/tree/main/classes/Blueprints/Attributes) of this repository. They reflect the properties you would set for a given field in a YAML blueprint. For some properties I created variants since different fields use the same property name but with different meanings (like `max` in a `number` field vs. `max` in a `date` field) and I wanted to keep them unambiguous in PHP.
261262

262-
`Accept, After, Api, Autocomplete, Autofocus, Before, Blueprint, Buttons, Calendar, Columns, ColumnsCount, Converter, Counter, CustomType, DefaultValue, Disabled, Display, EmptyValue, ExtendsField, Fieldsets, Fields, Files, Font, Format, GenericAttribute, Grow, Help, Icon, Image, Info, Inline, Label, Layout, LayoutSettings, Layouts, Link, Marks, Max, MaxDate, MaxRange, MaxTime, MaxLength, Min, MinDate, MinLength, MinRange, MinTime, Multiple, Nodes, Numbered, Options, Path, Pattern, Placeholder, Prepend, Property, Query, Range, Required, Reset, Search, Separator, Size, SortBy, Sortable, Spellcheck, Step, Store, Subpages, Sync, Text, Theme, Time, TimeNotation, Tooltip, Translate, Type, Uploads, When, Width, Wizard`
263+
`Alpha, Accept, After, Api, Autocomplete, Autofocus, Before, Blueprint, Buttons, Calendar, Columns, ColumnsCount, Converter, Counter, CustomType, DefaultValue, Disabled, Display, EmptyValue, ExtendsField, Fieldsets, Fields, Files, Font, Format, GenericAttribute, Grow, Help, Icon, Image, Info, Inline, Label, Layout, LayoutSettings, Layouts, Link, Marks, Max, MaxDate, MaxRange, MaxTime, MaxLength, Min, MinDate, MinLength, MinRange, MinTime, Mode, Multiple, Nodes, Numbered, Options, Path, Pattern, Placeholder, Prepend, Property, Query, Range, Required, Reset, Search, Separator, Size, SortBy, Sortable, Spellcheck, Step, Store, Subpages, Sync, Text, Theme, Time, TimeNotation, Tooltip, Translate, Type, Uploads, When, Width, Wizard`
263264

264265
### Benefits of using this plugin
265266

@@ -371,6 +372,7 @@ You will use the `*::make()`-helpers to create a blueprint definition in a PHP b
371372
This will also give you the benefit of not having any blueprint files at all.
372373

373374
**site/plugins/example/models/ArticlePage.php**
375+
374376
```php
375377
<?php
376378

@@ -388,13 +390,13 @@ class ProductPage extends \Kirby\Cms\Page
388390
CustomType('qrcode'),
389391
Property('Custom key', 'custom data'),
390392
]
391-
public Kirby\Content\Field $qrcode;
393+
public \Kirby\Content\Field $qrcode;
392394
393395
#[
394396
Type(FieldTypes::EMAIL),
395397
Placeholder('Email Field from Property')
396398
]
397-
public Kirby\Content\Field $email;
399+
public \Kirby\Content\Field $email;
398400
399401
#[
400402
Blueprint
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bnomei\Blueprints\Attributes;
4+
5+
use Attribute;
6+
7+
#[Attribute(Attribute::TARGET_PROPERTY)]
8+
class Alpha extends GenericAttribute
9+
{
10+
/**
11+
* Use the alpha option (default: false) to activate alpha transparency support
12+
*/
13+
public function __construct(
14+
public bool $alpha = false
15+
) {}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bnomei\Blueprints\Attributes;
4+
5+
use Attribute;
6+
7+
#[Attribute(Attribute::TARGET_PROPERTY)]
8+
class Mode extends GenericAttribute
9+
{
10+
/**
11+
* With the mode option you control which elements of the color field are available. Possible values: picker, input, options.
12+
*
13+
* @param string $mode
14+
*/
15+
public function __construct(
16+
public string $mode
17+
) {}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bnomei\Blueprints;
4+
5+
trait HasFluentGetter
6+
{
7+
public function __get(string $name): mixed
8+
{
9+
// fluent getter for dynamic properties
10+
if (property_exists($this, 'properties') && is_array($this->properties) && array_key_exists($name, $this->properties)) {
11+
return $this->properties[$name];
12+
}
13+
14+
return null;
15+
}
16+
}

classes/Blueprints/HasFluentSetter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
trait HasFluentSetter
66
{
7+
// TODO: refactor to __set
78
public function __call(string $name, array $arguments = []): self
89
{
910
// fluent setter for properties

classes/Blueprints/HasProperties.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public function toArray(): array
4040
return $data;
4141
}
4242

43+
public function properties(array $merge): self
44+
{
45+
$this->properties = array_merge($this->properties, $merge);
46+
47+
return $this;
48+
}
49+
4350
public function property(string $key, mixed $value): self
4451
{
4552
$this->properties[$key] = $value;

classes/Blueprints/Schema/Column.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @method self sections(Section[] $sections)
1111
* @method self id(string $id)
1212
* @method self fields(Field[] $fields)
13+
* @method self sticky(bool $sticky)
1314
*/
1415
class Column
1516
{

classes/Blueprints/Schema/Field.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bnomei\Blueprints\Schema;
44

5+
use Bnomei\Blueprints\HasFluentGetter;
56
use Bnomei\Blueprints\HasFluentSetter;
67
use Bnomei\Blueprints\HasProperties;
78
use Bnomei\Blueprints\HasStaticMake;
@@ -12,11 +13,13 @@
1213
* @method self id(string|null $id)
1314
* @method self label(array|string|null $label)
1415
* @method self width(float|string|null $width)
16+
* @method self extends(string|null $extends)
1517
* @method self property(string $name, mixed $value)
1618
* @method self properties(array $properties)
1719
*/
1820
class Field implements JsonSerializable
1921
{
22+
use HasFluentGetter;
2023
use HasFluentSetter;
2124
use HasProperties;
2225
use HasStaticMake;
@@ -29,6 +32,7 @@ public function __construct(
2932
public string|array|null $label = null,
3033
public array $properties = [],
3134
public string|float|null $width = null,
35+
public ?string $extends = null,
3236
) {
3337
$this->type ??= $type; // allow override from inheriting class
3438
}

classes/Blueprints/Schema/File.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,46 @@ public static function make(
4848
): self {
4949
return new self(...func_get_args()); // @phpstan-ignore-line
5050
}
51+
52+
public function accept(
53+
string|array|null $extension = null,
54+
string|array|null $mime = null,
55+
?int $maxheight = null,
56+
?int $maxsize = null,
57+
?int $maxwidth = null,
58+
?int $minheight = null,
59+
?int $minsize = null,
60+
?int $minwidth = null,
61+
?string $orientation = null, // landscape/square/portrait
62+
string|array|null $type = null,
63+
array $properties = [],
64+
): self {
65+
$this->accept = FileAccept::make(...func_get_args()); // @phpstan-ignore-line;
66+
67+
return $this;
68+
}
69+
70+
public function image(
71+
?string $back = null,
72+
?string $color = null,
73+
?string $icon = null,
74+
?string $query = null,
75+
): self {
76+
$this->image = FileImage::make(...func_get_args()); // @phpstan-ignore-line;
77+
78+
return $this;
79+
}
80+
81+
public function options(
82+
bool|array $changeName = true,
83+
bool|array $replace = true,
84+
bool|array $delete = true,
85+
bool|array $read = true,
86+
bool|array $update = true,
87+
array $properties = [],
88+
): self {
89+
$this->options = FileOptions::make(...func_get_args()); // @phpstan-ignore-line
90+
91+
return $this;
92+
}
5193
}

classes/Blueprints/Schema/Page.php

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
* @method self sections(Section[] $sections)
1111
* @method self columns(Column[] $columns)
1212
* @method self fields(Field[] $fields)
13+
* @method self title(string $title)
14+
* @method self num(string $num)
15+
* @method self icon(string|Icon $icon)
1316
*/
1417
class Page
1518
{
1619
use HasFluentSetter;
1720
use IsArrayable;
1821

1922
public function __construct(
20-
public string $title, // TODO: should be an string OR array of languages
23+
public mixed $title,
2124
public ?string $num = null,
2225
public mixed $status = null,
2326
public mixed $icon = null,
@@ -42,7 +45,7 @@ public function __construct(
4245
* @param array<Field> $fields
4346
*/
4447
public static function make(
45-
string $title,
48+
mixed $title,
4649
?string $num = null,
4750
mixed $status = null,
4851
mixed $icon = null,
@@ -56,4 +59,54 @@ public static function make(
5659
): self {
5760
return new self(...func_get_args()); // @phpstan-ignore-line
5861
}
62+
63+
public function status(
64+
string|array $draft,
65+
string|array $unlisted,
66+
string|array $listed,
67+
): self {
68+
$this->status = PageStatus::make(...func_get_args()); // @phpstan-ignore-line;
69+
70+
return $this;
71+
}
72+
73+
public function image(
74+
?string $back = null,
75+
?string $color = null,
76+
?string $icon = null,
77+
?string $query = null,
78+
): self {
79+
$this->image = PageImage::make(...func_get_args()); // @phpstan-ignore-line;
80+
81+
return $this;
82+
}
83+
84+
public function options(
85+
bool|array $changeSlug = true,
86+
bool|array $changeStatus = true,
87+
bool|array $changeTemplate = true,
88+
bool|array $changeTitle = true,
89+
bool|array $create = true,
90+
bool|array $delete = true,
91+
bool|array $duplicate = true,
92+
bool|string $preview = true,
93+
bool|array $read = true,
94+
bool|array $sort = true,
95+
bool|array $update = true,
96+
array $properties = [],
97+
): self {
98+
$this->options = PageOptions::make(...func_get_args()); // @phpstan-ignore-line
99+
100+
return $this;
101+
}
102+
103+
public function navigation(
104+
string|array $status = 'all',
105+
string|array $template = 'all',
106+
string $sortBy = 'title asc',
107+
): self {
108+
$this->navigation = PageNavigation::make(...func_get_args()); // @phpstan-ignore-line
109+
110+
return $this;
111+
}
59112
}

0 commit comments

Comments
 (0)