PluginProbe
Blocks – Reusable Content, Shortcodes & Site Variables / trunk
Blocks – Reusable Content, Shortcodes & Site Variables vtrunk
26.09.03.15 26.08.31.21 26.08.22.20 26.08.22.22 26.08.22.17 26.08.22.13 26.08.21.19 26.08.07.23 26.07.19.14 26.07.13.21 26.07.13.17 26.07.12.13 026.07.07.21 026.07.05.18 026.06.26.20 026.06.26.21 026.06.08.20 026.05.13.14 026.04.29.10 trunk 026.02.22.22 026.03.16.23 026.04.23.13
blocks / src / Settings / FieldDefinition.php

FieldDefinition.php in Blocks – Reusable Content, Shortcodes & Site Variables trunk, at src/Settings/FieldDefinition.php

37 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace RenzoJohnson\Blocks\Settings;
6
7 \defined( 'ABSPATH' ) || exit;
8
9 final class FieldDefinition {
10 /**
11 * @param non-empty-list<SettingDefinition> $settings
12 * @param array<string, mixed> $render_args
13 * @throws \InvalidArgumentException When no setting is supplied.
14 */
15 public function __construct(
16 public readonly string $id,
17 public readonly string $label,
18 public readonly string $description,
19 public readonly FieldType $type,
20 public readonly array $settings,
21 public readonly array $render_args = array(),
22 public readonly Requirement $requirement = Requirement::Always,
23 // Descriptions are hard-escaped, so a documentation link is carried as
24 // data and rendered as its own anchor rather than as inline markup.
25 public readonly string $doc_url = '',
26 public readonly string $doc_label = '',
27 ) {
28 if ( array() === $settings ) {
29 throw new \InvalidArgumentException( 'A field must own at least one setting.' );
30 }
31 }
32
33 public function primary(): SettingDefinition {
34 return $this->settings[0];
35 }
36 }
37