-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d78025
commit 49e1416
Showing
22 changed files
with
461 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace SylvainJule; | ||
|
||
class ImageRadioFactory extends \Kirby\Blueprint\Factory { | ||
public static function apply(array $properties, array $factories): array | ||
{ | ||
|
||
foreach ($factories as $property => $class) { | ||
// skip non-existing properties, empty properties | ||
// or properties that are matching objects | ||
if ( | ||
isset($properties[$property]) === false || | ||
$properties[$property] === null || | ||
is_a($properties[$property], $class) === true | ||
) { | ||
continue; | ||
} | ||
|
||
$properties[$property] = $class::factory($properties[$property]); | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace SylvainJule; | ||
|
||
use Kirby\Blueprint\Factory; | ||
use Kirby\Blueprint\NodeIcon; | ||
use Kirby\Blueprint\NodeText; | ||
use Kirby\Blueprint\NodeString; | ||
use Kirby\Cms\ModelWithContent; | ||
|
||
|
||
class ImageRadioOption extends \Kirby\Option\Option { | ||
public function __construct( | ||
public string|int|float|null $value, | ||
public bool $disabled = false, | ||
public NodeIcon|null $icon = null, | ||
public NodeText|null $info = null, | ||
public NodeText|null $text = null, | ||
public NodeString|null $image = null, | ||
) { | ||
$this->text ??= new NodeText(['en' => $this->value]); | ||
} | ||
public static function factory(string|int|float|null|array $props): static | ||
{ | ||
|
||
$props = ImageRadioFactory::apply($props, [ | ||
'icon' => NodeIcon::class, | ||
'info' => NodeText::class, | ||
'text' => NodeText::class, | ||
'image' => NodeString::class, | ||
]); | ||
|
||
return new static(...$props); | ||
} | ||
public function render(ModelWithContent $model): array | ||
{ | ||
return [ | ||
'disabled' => $this->disabled, | ||
'icon' => $this->icon?->render($model), | ||
'info' => $this->info?->render($model), | ||
'text' => $this->text?->render($model), | ||
'image' => $this->image?->render($model), | ||
'value' => $this->value | ||
]; | ||
} | ||
} |
Oops, something went wrong.