File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 434434 'segment_provider ' => DefaultSegmentProvider::class,
435435 'preview_provider ' => DefaultPreviewProvider::class,
436436 'slug_generator ' => DefaultSlugGenerator::class,
437+ 'fallback_seo ' => [
438+ 'title ' => env ('APP_NAME ' , 'Home ' ),
439+ 'description ' => 'Powered by InspireCMS ' ,
440+ 'keywords ' => '' ,
441+ 'image ' => null ,
442+ ],
437443 ],
438444
439445 'sitemap ' => [
Original file line number Diff line number Diff line change @@ -217,7 +217,28 @@ public function getSeo(?string $locale = null)
217217 {
218218 $ seo = collect ($ this ->seo );
219219
220- return $ seo ->get ($ locale ?? $ this ->getLocale ()) ?? $ seo ->get ($ this ->getFallbackLocale ());
220+ $ locale ??= $ this ->getLocale ();
221+
222+ $ result = $ seo ->get ($ locale );
223+
224+ // Using fallback locale
225+ if (! $ result ) {
226+ if (($ fallbackLocale = $ this ->getFallbackLocale ()) && ($ fallbackSeo = $ seo ->get ($ fallbackLocale ))) {
227+ $ fallbackSeo ->locale = $ fallbackLocale ;
228+ $ result = $ fallbackSeo ;
229+ }
230+ } else {
231+ $ result ->locale = $ locale ;
232+ }
233+
234+ // Using default SEO data if not found
235+ if (! $ result ) {
236+ $ result = SeoDto::fromArray ([
237+ 'locale ' => $ locale ,
238+ ]);
239+ }
240+
241+ return $ result ;
221242 }
222243
223244 public function isRedirectable (): bool
Original file line number Diff line number Diff line change 55use Illuminate \Contracts \Support \Htmlable ;
66use Illuminate \Support \Collection ;
77use Illuminate \Support \HtmlString ;
8+ use SolutionForest \InspireCms \InspireCmsConfig ;
89use SolutionForest \InspireCms \Support \Base \Dtos \BaseDto ;
910
1011class SeoDto extends BaseDto
@@ -259,6 +260,29 @@ public static function fromArray(array $parameters)
259260
260261 $ dto = parent ::fromArray ($ parameters );
261262
263+ $ fallbackSeo = InspireCmsConfig::get ('frontend.fallback_seo ' , []);
264+ $ fallbackExtraMapper = [
265+ 'title ' => ['ogTitle ' ],
266+ 'description ' => ['ogDescription ' ],
267+ 'image ' => ['ogImage ' ],
268+ ];
269+ if (is_array ($ fallbackSeo ) && ! empty ($ fallbackSeo )) {
270+ foreach ($ fallbackSeo as $ key => $ value ) {
271+ $ keysToMap = array_unique (array_merge (
272+ [$ key ],
273+ $ fallbackExtraMapper [$ key ] ?? []
274+ ));
275+ foreach ($ keysToMap ?? [] as $ mappedKey ) {
276+ if (! property_exists ($ dto , $ mappedKey )) {
277+ continue ;
278+ }
279+ if (! isset ($ dto ->{$ mappedKey }) || empty ($ dto ->{$ mappedKey })) {
280+ $ dto ->{$ mappedKey } = $ value ;
281+ }
282+ }
283+ }
284+ }
285+
262286 return $ dto ;
263287 }
264288
You can’t perform that action at this time.
0 commit comments