From 7b9346c08236b0662ae4693970d1990c477b82b9 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Sun, 27 Feb 2022 17:12:25 +0000 Subject: [PATCH] Avoid PHP undefined index notices on extension pages --- CRM/Admin/Page/Extensions.php | 28 +++++++++++++++++-- templates/CRM/Admin/Page/ExtensionDetails.tpl | 19 +++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CRM/Admin/Page/Extensions.php b/CRM/Admin/Page/Extensions.php index b8250a69a4..d601d1b05a 100644 --- a/CRM/Admin/Page/Extensions.php +++ b/CRM/Admin/Page/Extensions.php @@ -246,7 +246,7 @@ class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic { if (!empty($compat[$info->key]['obsolete'])) { continue; } - $row = (array) $info; + $row = self::fillMissingInfoKeys((array) $info); $row['id'] = $info->key; $row['upgradelink'] = ''; $action = CRM_Core_Action::UPDATE; @@ -330,7 +330,31 @@ class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic { * @return array */ public static function createExtendedInfo(CRM_Extension_Info $obj) { - return CRM_Extension_System::createExtendedInfo($obj); + return self::fillMissingInfoKeys(CRM_Extension_System::createExtendedInfo($obj)); + } + + /** + * Extension templates expect certain keys to always be set, but these might be missing from the relevant info.xml files + * This ensures the expect keys are always set. + * + * @param array $info + * @return array + */ + private static function fillMissingInfoKeys(array $info) { + $defaultKeys = [ + 'urls' => [], + 'authors' => [], + 'version' => '', + 'description' => '', + 'license' => '', + 'releaseDate' => '', + 'downloadUrl' => FALSE, + 'compatibility' => FALSE, + 'develStage' => FALSE, + 'comments' => FALSE, + ]; + + return array_merge($defaultKeys, $info); } } diff --git a/templates/CRM/Admin/Page/ExtensionDetails.tpl b/templates/CRM/Admin/Page/ExtensionDetails.tpl index 7832acbe91..aec11823d7 100644 --- a/templates/CRM/Admin/Page/ExtensionDetails.tpl +++ b/templates/CRM/Admin/Page/ExtensionDetails.tpl @@ -1,5 +1,5 @@ - {if !empty($extension.urls)} + {if $extension.urls} {foreach from=$extension.urls key=label item=url} {/foreach} @@ -17,7 +17,7 @@ {/foreach} - {if !empty($extension.comments)} + {if $extension.comments} @@ -31,7 +31,7 @@ - {if !empty($extension.develStage)} + {if $extension.develStage} @@ -54,12 +54,19 @@ + {if $extension.downloadUrl} + + + + {/if}
{$label|escape}{$url|escape}
{ts}Comments{/ts}{$extension.comments|escape}
{ts}License{/ts}{$extension.license|escape}
{ts}Development stage{/ts}{$extension.develStage|escape}
{ts}Compatible with{/ts} - {foreach from=$extension.compatibility.ver item=ver} - {$ver|escape}   - {/foreach} + {if $extension.compatibility} + {foreach from=$extension.compatibility.ver item=ver} + {$ver|escape}   + {/foreach} + {/if}
{ts}Local path{/ts}{if !empty($extension.path)}{$extension.path|escape}{/if}
{ts}Download location{/ts}{$extension.downloadUrl|escape}
-- 2.25.1