| 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 |
|