Skip to content

Commit

Permalink
fix : title for alt when document or image on form modal
Browse files Browse the repository at this point in the history
  • Loading branch information
webplusmultimedia committed Apr 25, 2024
1 parent 3c100b0 commit 8c3b699
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions resources/lang/en/gallery-json-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
'tooltip.edit-button-custom-property' => 'Edit custom properties',
'title.edit-modal-form-for-customs-properties' => 'Edit custom properties',
'infoList.document.nothing-to-show' => 'Nothing to show',
'form.alt.label.media' => 'Alt',
'form.alt.label.document' => 'Document title',
];
3 changes: 3 additions & 0 deletions resources/lang/fr/gallery-json-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
'Drag&Drop' => 'Drag & Drop ou cliquer ICI',
'tooltip.edit-button-custom-property' => 'Edition des propriétés personnalisées',
'title.edit-modal-form-for-customs-properties' => 'Edition des propriétés personnalisées',
'infoList.document.nothing-to-show' => 'Pas de document',
'form.alt.label.media' => 'Alt',
'form.alt.label.document' => 'Titre du Document',
];
13 changes: 10 additions & 3 deletions src/Form/Concerns/HasCustomProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getCustomPropertiesAction(): ?Action
return $state[$key]['customProperties'];
})
->label(trans('gallery-json-media::gallery-json-media.title.edit-modal-form-for-customs-properties'))
->form(fn (array $arguments) => $this->getMinimumFieldForCustomEditField($arguments, $this->getState()))
->form(fn (array $arguments) => $this->getMinimumFieldForCustomEditField($arguments))
->action(function (array $arguments, array $data, Form $form, JsonMediaGallery $component) {
$key = $arguments['key'];
$state = $component->getState();
Expand All @@ -104,9 +104,16 @@ public function getCustomPropertiesAction(): ?Action
return null;
}

private function getMinimumFieldForCustomEditField(array $arguments, array $state): array
private function getMinimumFieldForCustomEditField(array $arguments): array
{
return array_merge([TextInput::make('alt')->required()->helperText('Alternative text image')], $this->getCustomPropertiesSchema());
$key = $arguments['key'];
$state = $this->getState();
$mimeType = $state[$key]['mime_type'];
$label = $this->isImageFile($mimeType) ?
trans('gallery-json-media::gallery-json-media.form.alt.label.media')
: trans('gallery-json-media::gallery-json-media.form.alt.label.document');

return array_merge([TextInput::make('alt')->label($label)->required()], $this->getCustomPropertiesSchema());
}

private function isImageFile(string $mimeType): bool
Expand Down

0 comments on commit 8c3b699

Please sign in to comment.