first()['value'] ?? null;
}),
Setting::classAttribute(),
Setting::description(),
];
}
public function sanitizeValue($value, array $field)
{
if (!Collection::make($field['table_list'])->pluck('value')->contains($value)) {
return;
}
return $value;
}
public function usesAssets(): bool
{
return true;
}
public function enqueue(array $field): void
{
// wp-components: a WordPress core stylesheet (not something this plugin ships), the same one the block
// editor uses. render() below reuses its real .components-button(-group) classes and colors, not a
// look-alike, so this field genuinely looks like Gutenberg instead of an older wp-admin button.
wp_enqueue_style('wp-components');
}
/**
* The stored value, when it is one of the choices.
*/
public function displayValue($value, array $field, array $args): string
{
return Display::choice($value, $field);
}
public function render(array $field, $value): void
{
$rows = Collection::make($field['table_list']);
// Scopes the style below to this field: several button-group fields can be on the same options page.
$groupId = $field['field_name'] . '_group';
print('