@@ -95,6 +95,36 @@ public static function localeOptions(): array
9595
9696 private const OVERRIDE_KEYS = ['title ' , 'description ' , 'button_text ' , 'button2_text ' ];
9797
98+ private static function isAbsoluteImageUrl (?string $ value ): bool
99+ {
100+ if (! is_string ($ value ) || trim ($ value ) === '' ) {
101+ return false ;
102+ }
103+
104+ return str_starts_with ($ value , 'http:// ' ) || str_starts_with ($ value , 'https:// ' );
105+ }
106+
107+ private static function fillImageFromInputs ($ request , $ model ): void
108+ {
109+ $ path = trim ((string ) $ request ->get ('image_path_input ' , '' ));
110+ $ url = trim ((string ) $ request ->get ('image_url_input ' , '' ));
111+
112+ // URL wins when both are provided.
113+ if ($ url !== '' ) {
114+ $ model ->image = $ url ;
115+ return ;
116+ }
117+
118+ if ($ path !== '' ) {
119+ $ model ->image = ltrim ($ path , '/ ' );
120+ return ;
121+ }
122+
123+ if ($ request ->exists ('image_path_input ' ) || $ request ->exists ('image_url_input ' )) {
124+ $ model ->image = null ;
125+ }
126+ }
127+
98128 private static function parseOverrideAttribute (string $ attribute ): ?array
99129 {
100130 if (! str_starts_with ($ attribute , 'override_ ' ) || strlen ($ attribute ) < 12 ) {
@@ -227,9 +257,32 @@ public function fields(Request $request): array
227257 ->help ('Leave empty to hide second button. Lang key or plain text. ' ),
228258 Boolean::make ('Open second link in new tab ' , 'open_second_new_tab ' )
229259 ->help ('Open the second button link in a new window/tab. ' ),
230- Text::make ('Image ' , 'image ' )
260+ Text::make ('Image (saved value) ' , 'image ' )
261+ ->exceptOnForms ()
231262 ->nullable ()
232- ->help ('Path from site root e.g. images/dream-jobs/dream_jobs_bg.png (no leading slash), or full URL. Used as slide background. ' ),
263+ ->help ('Stored image reference used by the homepage slider. ' ),
264+ Text::make ('Image path (site root) ' , 'image_path_input ' )
265+ ->onlyOnForms ()
266+ ->nullable ()
267+ ->resolveUsing (function () {
268+ $ image = $ this ->resource ->image ;
269+ return self ::isAbsoluteImageUrl ($ image ) ? '' : (string ) ($ image ?? '' );
270+ })
271+ ->fillUsing (function ($ request , $ model ) {
272+ self ::fillImageFromInputs ($ request , $ model );
273+ })
274+ ->help ('Option 1: local path like images/dream-jobs/dream_jobs_bg.png (no leading slash). ' ),
275+ Text::make ('Image URL (full) ' , 'image_url_input ' )
276+ ->onlyOnForms ()
277+ ->nullable ()
278+ ->resolveUsing (function () {
279+ $ image = $ this ->resource ->image ;
280+ return self ::isAbsoluteImageUrl ($ image ) ? (string ) $ image : '' ;
281+ })
282+ ->fillUsing (function ($ request , $ model ) {
283+ self ::fillImageFromInputs ($ request , $ model );
284+ })
285+ ->help ('Option 2: full URL, e.g. https://codeweek-resources.s3.eu-west-1.amazonaws.com/... ' ),
233286 Number::make ('Position ' , 'position ' )
234287 ->min (0 )
235288 ->default (0 )
0 commit comments