Skip to content

Commit 9556170

Browse files
Merge pull request #94 from relaticle/feat/field-description-help-text
feat: add field description/help text support
2 parents b86380c + df3265c commit 9556170

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

config/custom-fields.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
CustomFieldsFeature::UI_TABLE_COLUMNS,
5555
CustomFieldsFeature::UI_TOGGLEABLE_COLUMNS,
5656
CustomFieldsFeature::UI_TABLE_FILTERS,
57+
CustomFieldsFeature::FIELD_DESCRIPTION,
5758
CustomFieldsFeature::UI_FIELD_WIDTH_CONTROL,
5859
CustomFieldsFeature::SYSTEM_MANAGEMENT_INTERFACE,
5960
CustomFieldsFeature::SYSTEM_SECTIONS,

resources/lang/en/custom-fields.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'name_helper_text' => "The field's label shown in the table's and form's.",
3838
'code' => 'Code',
3939
'code_helper_text' => 'Unique code to identify this field throughout the resource.',
40+
'description' => 'Description',
4041
'settings' => 'Settings',
4142
'encrypted' => 'Encrypted',
4243
'encrypted_help' => 'When enabled, this field\'s values will be stored securely using encryption.',

src/Data/CustomFieldSettingsData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct(
2323
public bool $allow_multiple = false,
2424
public int $max_values = 1,
2525
public bool $unique_per_entity_type = false,
26+
public ?string $description = null,
2627
public VisibilityData $visibility = new VisibilityData,
2728
public array $additional = [],
2829
) {

src/Enums/CustomFieldsFeature.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum CustomFieldsFeature: string
1818
case FIELD_MULTI_VALUE = 'field_multi_value';
1919
case FIELD_UNIQUE_VALUE = 'field_unique_value';
2020
case FIELD_VALIDATION_RULES = 'field_validation_rules';
21+
case FIELD_DESCRIPTION = 'field_description';
2122

2223
// Table/UI integration features
2324
case UI_TABLE_COLUMNS = 'ui_table_columns';

src/Filament/Integration/Base/AbstractFormComponent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ protected function configure(
5555
$field
5656
->name($customField->getFieldName())
5757
->label($customField->name)
58+
->helperText(
59+
FeatureManager::isEnabled(CustomFieldsFeature::FIELD_DESCRIPTION)
60+
? ($customField->settings->description ?? null)
61+
: null
62+
)
5863
->afterStateHydrated(
5964
fn (mixed $component, mixed $state, mixed $record): mixed => $component->state(
6065
$this->transformHydratedValue(

src/Filament/Management/Schemas/FieldForm.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Filament\Forms\Components\Repeater;
1111
use Filament\Forms\Components\Repeater\TableColumn;
1212
use Filament\Forms\Components\Select;
13+
use Filament\Forms\Components\Textarea;
1314
use Filament\Forms\Components\TextInput;
1415
use Filament\Forms\Components\Toggle;
1516
use Filament\Schemas\Components\Component;
@@ -268,6 +269,12 @@ public static function schema(bool $withOptionsRelationship = true): array
268269
$set('code', Str::of($state)->slug('_')->toString());
269270
}),
270271
]),
272+
Textarea::make('settings.description')
273+
->label(__('custom-fields::custom-fields.field.form.description'))
274+
->maxLength(255)
275+
->rows(2)
276+
->columnSpanFull()
277+
->visible(fn (): bool => FeatureManager::isEnabled(CustomFieldsFeature::FIELD_DESCRIPTION)),
271278
Fieldset::make(
272279
__(
273280
'custom-fields::custom-fields.field.form.settings'

0 commit comments

Comments
 (0)