99use Drupal \Core \Entity \EntityTypeManagerInterface ;
1010use Drupal \Core \Serialization \Yaml ;
1111use Drupal \Core \StringTranslation \StringTranslationTrait ;
12+ use Drupal \os2forms_sync \Entity \AvailableWebform ;
1213use Drupal \os2forms_sync \Entity \ImportedWebform ;
1314use Drupal \webform \Entity \Webform ;
1415use Drupal \webform \WebformEntityStorageInterface ;
@@ -314,7 +315,8 @@ public function deleteWebform(WebformInterface $webform): void {
314315 /**
315316 * Get available published webforms.
316317 *
317- * @phpstan-return array<mixed>
318+ * @return \Drupal\os2forms_sync\Entity\AvailableWebform[]|array
319+ * The available webforms.
318320 */
319321 public function getAvailableWebforms (): array {
320322 $ sources = array_unique ($ this ->settings ->getSources ());
@@ -329,16 +331,22 @@ public function getAvailableWebforms(): array {
329331 );
330332
331333 if ($ ttl > 0 && $ hit = $ this ->cache ->get ($ cacheKey )) {
332- return $ hit ->data ;
334+ $ webforms = $ hit ->data ;
333335 }
336+ else {
337+ $ webforms = $ this ->fetchAvailableWebforms ($ sources );
334338
335- $ webforms = $ this ->fetchAvailableWebforms ($ sources );
336-
337- if ($ ttl > 0 ) {
338- $ this ->cache ->set ($ cacheKey , $ webforms , time () + $ ttl );
339+ if ($ ttl > 0 ) {
340+ $ this ->cache ->set ($ cacheKey , $ webforms , time () + $ ttl );
341+ }
339342 }
340343
341- return $ webforms ;
344+ return array_map (
345+ static function ($ webform ) {
346+ return new AvailableWebform ($ webform );
347+ },
348+ $ webforms
349+ );
342350 }
343351
344352 /**
@@ -367,12 +375,10 @@ public function fetchAvailableWebforms(array $sources): array {
367375 * @param string $url
368376 * The webform url.
369377 *
370- * @return array |null
378+ * @return \Drupal\os2forms_sync\Entity\AvailableWebform |null
371379 * The webform if any.
372- *
373- * @phpstan-return null|array<string, mixed>
374380 */
375- public function getAvailableWebform (string $ url ): ?array {
381+ public function getAvailableWebform (string $ url ): ?AvailableWebform {
376382 $ webforms = $ this ->getAvailableWebforms ();
377383 foreach ($ webforms as $ webform ) {
378384 if ($ url === ($ webform ['links ' ]['self ' ] ?? NULL )) {
0 commit comments