private function themeInfoToMediaItem($themeKey, $isCurrent = false)
{
$themeInfo = Gdn::themeManager()->getThemeInfo($themeKey);
if (!$themeInfo) {
throw new Exception(sprintf(t('Theme with key %s not found.'), $themeKey));
}
$options = val('Options', $themeInfo, []);
$iconUrl = val('IconUrl', $themeInfo, val('ScreenshotUrl', $themeInfo, "applications/dashboard/design/images/theme-placeholder.svg"));
$themeName = val('Name', $themeInfo, val('Index', $themeInfo, $themeKey));
$themeUrl = val('ThemeUrl', $themeInfo, '');
$description = val('Description', $themeInfo, '');
$version = val('Version', $themeInfo, '');
$newVersion = val('NewVersion', $themeInfo, '');
$attr = [];
if ($isCurrent) {
$attr['class'] = 'media-callout-grey-bg';
}
$media = new MediaItemModule($themeName, $themeUrl, $description, 'div', $attr);
$media->setView('media-callout');
$media->addOption('has-options', !empty($options));
$media->addOption('has-upgrade', $newVersion != '' && version_compare($newVersion, $version, '>'));
$media->addOption('new-version', val('NewVersion', $themeInfo, ''));
$media->setImage($iconUrl);
if ($isCurrent) {
$media->addOption('is-current', $isCurrent);
}
// Meta
// Add author meta
$author = val('Author', $themeInfo, '');
$authorUrl = val('AuthorUrl', $themeInfo, '');
$media->addMetaIf($author != '', '<span class="media-meta author">' . sprintf('Created by %s', $authorUrl != '' ? anchor($author, $authorUrl) : $author) . '</span>');
// Add version meta
$version = val('Version', $themeInfo, '');
$media->addMetaIf($version != '', '<span class="media-meta version">' . sprintf(t('Version %s'), $version) . '</span>');
// Add requirements meta
$requirements = val('RequiredApplications', $themeInfo, []);
$required = [];
$requiredString = '';
if (!empty($requirements)) {
foreach ($requirements as $requirement => $versionInfo) {
$required[] = printf(t('%1$s Version %2$s'), $requirement, $versionInfo);
}
}
if (!empty($required)) {
$requiredString .= '<span class="media-meta requirements">' . t('Requires: ') . implode(', ', $required) . '</span>';
}
$media->addMetaIf($requiredString != '', $requiredString);
return $media;
}