File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -274,11 +274,24 @@ public function setLocale(
274274 }
275275
276276 /**
277- * @param null|Alternate[] $value
277+ * @param null|Alternate[]|array<string, string> $value
278278 * @return $this
279279 */
280280 public function setAlternates (?array $ value ): static
281281 {
282+ if ($ value ) {
283+ $ value = collect ($ value )
284+ ->map (function ($ href , $ hrelang ) {
285+ if ($ href instanceof Alternate) {
286+ return $ href ;
287+ }
288+
289+ return new Alternate ($ hrelang , $ href );
290+ })
291+ ->values ()
292+ ->all ();
293+ }
294+
282295 if ($ this ->standard ) {
283296 $ this ->standard ->alternates = $ value ;
284297 }
Original file line number Diff line number Diff line change 133133 expect ($ clone ->customTags [0 ])->not ->toBe ($ base ->customTags [0 ]);
134134 expect ($ clone ->customTags [0 ]->properties )->not ->toBe ($ base ->customTags [0 ]->properties );
135135});
136+
137+ it ('can set alternates using assoc array ' , function () {
138+ $ manager = new SeoManager (
139+ standard: new Standard (
140+ title: 'foo ' ,
141+ canonical: 'bar ' ,
142+ ),
143+ opengraph: new OpenGraph (
144+ title: 'foo ' ,
145+ url: 'bar ' ,
146+ ),
147+ );
148+
149+ $ manager ->setAlternates ([
150+ 'fr ' => 'example.com/fr ' ,
151+ 'en ' => 'example.com/en ' ,
152+ 'x-default ' => 'example.com/en ' ,
153+ ]);
154+
155+ expect ($ manager ->standard ->alternates )->toHaveLength (3 );
156+ expect ($ manager ->standard ->alternates [0 ]->hreflang )->toBe ('fr ' );
157+ expect ($ manager ->standard ->alternates [0 ]->href )->toBe ('example.com/fr ' );
158+ });
You can’t perform that action at this time.
0 commit comments