Skip to content

Commit ceda119

Browse files
committed
Kirby 4 compatibility (2.0.0)
1 parent c4e364d commit ceda119

18 files changed

+445
-412
lines changed

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Add illustrations to checkboxes.
88

99
## Overview
1010

11-
> This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, please consider [making a donation of your choice](https://www.paypal.me/sylvainjl) or purchasing your license(s) through [my affiliate link](https://a.paddle.com/v2/click/1129/36369?link=1170).
11+
> This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, please consider [making a donation of your choice](https://www.paypal.me/sylvainjl).
1212
1313
- [1. Installation](#1-installation)
1414
- [2. Setup](#2-setup)
@@ -22,7 +22,7 @@ Add illustrations to checkboxes.
2222

2323
## 1. Installation
2424

25-
> If you are looking to use this field with Kirby 2, please switch to the `kirby-2` branch.
25+
> Kirby 3: Up to 1.0.6. Kirby 4: 2.0.0+
2626
2727
Download and copy this repository to ```/site/plugins/imageboxes```
2828

@@ -143,18 +143,6 @@ myimageboxes:
143143
mobile: false
144144
```
145145

146-
#### 4.5. `gap`
147-
148-
![gap](https://user-images.githubusercontent.com/14079751/48333926-58bc1880-e659-11e8-8920-6ad913c63529.jpg)
149-
150-
Whether the field should add a `1rem` gap between each input, K2-like. Default is `false`.
151-
152-
```yaml
153-
myimageboxes:
154-
type: imageboxes
155-
gap: false
156-
```
157-
158146
<br/>
159147

160148
## 5. License

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Add illustrations to Kirby's checkboxes",
44
"type": "kirby-plugin",
55
"license": "MIT",
6-
"version": "1.0.6",
6+
"version": "2.0.0",
77
"authors": [
88
{
99
"name": "Sylvain Julé",

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/fields/imageboxes.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
namespace SylvainJule;
4+
35
require_once dirname(__DIR__) . '/options/imageboxes-optionsapi.php';
46
require_once dirname(__DIR__) . '/options/imageboxes-optionsquery.php';
7+
require_once dirname(__DIR__) . '/options/imageboxes-factory.php';
8+
require_once dirname(__DIR__) . '/options/imageboxes-option.php';
59
require_once dirname(__DIR__) . '/options/imageboxes-options.php';
6-
10+
require_once dirname(__DIR__) . '/options/imageboxes.php';
711

812
$base = require kirby()->root('kirby') . '/config/fields/checkboxes.php';
913

@@ -22,9 +26,6 @@
2226
'back' => function($back = false) {
2327
return $back;
2428
},
25-
'gap' => function($gap = false) {
26-
return $gap;
27-
},
2829
'mobile' => function($mobile = false) {
2930
return $mobile;
3031
},
@@ -39,9 +40,12 @@
3940
--------------------------------*/
4041

4142
$base = array_replace_recursive($base, array(
42-
'computed' => array(
43-
'options' => function() {
44-
return ImageBoxesOptions::factory($this->options(), $this->props, $this->model());
43+
'methods' => array(
44+
'getOptions' => function() {
45+
$props = \Kirby\Field\FieldOptions::polyfill($this->props);
46+
$options = ImageBoxes::factory($props['options']);
47+
48+
return $options->render($this->model());
4549
},
4650
),
4751
));

lib/options/imageboxes-factory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace SylvainJule;
4+
5+
class ImageBoxesFactory extends \Kirby\Blueprint\Factory {
6+
public static function apply(array $properties, array $factories): array
7+
{
8+
9+
foreach ($factories as $property => $class) {
10+
// skip non-existing properties, empty properties
11+
// or properties that are matching objects
12+
if (
13+
isset($properties[$property]) === false ||
14+
$properties[$property] === null ||
15+
is_a($properties[$property], $class) === true
16+
) {
17+
continue;
18+
}
19+
20+
$properties[$property] = $class::factory($properties[$property]);
21+
}
22+
23+
return $properties;
24+
}
25+
}

lib/options/imageboxes-option.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace SylvainJule;
4+
5+
use Kirby\Blueprint\Factory;
6+
use Kirby\Blueprint\NodeIcon;
7+
use Kirby\Blueprint\NodeText;
8+
use Kirby\Blueprint\NodeString;
9+
use Kirby\Cms\ModelWithContent;
10+
11+
12+
class ImageBoxesOption extends \Kirby\Option\Option {
13+
public function __construct(
14+
public string|int|float|null $value,
15+
public bool $disabled = false,
16+
public NodeIcon|null $icon = null,
17+
public NodeText|null $info = null,
18+
public NodeText|null $text = null,
19+
public NodeString|null $image = null,
20+
) {
21+
$this->text ??= new NodeText(['en' => $this->value]);
22+
}
23+
public static function factory(string|int|float|null|array $props): static
24+
{
25+
26+
$props = ImageBoxesFactory::apply($props, [
27+
'icon' => NodeIcon::class,
28+
'info' => NodeText::class,
29+
'text' => NodeText::class,
30+
'image' => NodeString::class,
31+
]);
32+
33+
return new static(...$props);
34+
}
35+
public function render(ModelWithContent $model): array
36+
{
37+
return [
38+
'disabled' => $this->disabled,
39+
'icon' => $this->icon?->render($model),
40+
'info' => $this->info?->render($model),
41+
'text' => $this->text?->render($model),
42+
'image' => $this->image?->render($model),
43+
'value' => $this->value
44+
];
45+
}
46+
}

0 commit comments

Comments
 (0)