diff --git a/src/Plugin/ProjectBrowserSource/DrupalDotOrgJsonApi.php b/src/Plugin/ProjectBrowserSource/DrupalDotOrgJsonApi.php index 2865b4bb85493e885308b72d9d04385b6424702a..3df3025df610f89e9551d79c3dc55f5ef7828462 100644 --- a/src/Plugin/ProjectBrowserSource/DrupalDotOrgJsonApi.php +++ b/src/Plugin/ProjectBrowserSource/DrupalDotOrgJsonApi.php @@ -6,6 +6,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Html; use Drupal\Core\Extension\ExtensionVersion; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Url; use Drupal\project_browser\DevelopmentStatus; use Drupal\project_browser\MaintenanceStatus; use Drupal\project_browser\Plugin\ProjectBrowserSourceBase; @@ -396,6 +397,7 @@ class DrupalDotOrgJsonApi extends ProjectBrowserSourceBase { packageName: $project['attributes']['field_composer_namespace'] ?? 'drupal/' . $machine_name, categories: $module_categories, images: $project_images, + url: Url::fromUri('https://www.drupal.org/project/' . $machine_name), ); $returned_list[] = $project_object; } diff --git a/src/Plugin/ProjectBrowserSource/Recipes.php b/src/Plugin/ProjectBrowserSource/Recipes.php index d31c93d0f7c136d86b62ce7970a69eb305a6397a..079e4a33b4741331eb60b8398659bb354aece24c 100644 --- a/src/Plugin/ProjectBrowserSource/Recipes.php +++ b/src/Plugin/ProjectBrowserSource/Recipes.php @@ -13,6 +13,7 @@ use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileUrlGeneratorInterface; use Drupal\Core\Recipe\Recipe; +use Drupal\Core\Url; use Drupal\project_browser\Plugin\ProjectBrowserSourceBase; use Drupal\project_browser\ProjectBrowser\Project; use Drupal\project_browser\ProjectBrowser\ProjectsResultsPage; @@ -81,6 +82,10 @@ class Recipes extends ProjectBrowserSourceBase { $package = file_get_contents($path . '/composer.json'); $package = Json::decode($package); $package_name = $package['name']; + + if (array_key_exists('homepage', $package)) { + $url = Url::fromUri($package['homepage']); + } } $recipe = Yaml::decode($file->getContents()); @@ -110,6 +115,7 @@ class Recipes extends ProjectBrowserSourceBase { author: [], packageName: $package_name, type: ProjectType::Recipe, + url: $url ?? NULL, ); } $this->cacheBin->set($this->getPluginId(), $projects); diff --git a/src/ProjectBrowser/Project.php b/src/ProjectBrowser/Project.php index 301dd60ac444e5d9e059caad6c12344baab90c48..db1808be87ad1a7986e47f451e435d186194f934 100644 --- a/src/ProjectBrowser/Project.php +++ b/src/ProjectBrowser/Project.php @@ -94,8 +94,8 @@ class Project implements \JsonSerializable { * Author of the project in array format. * @param string $packageName * The Composer package name of this project, e.g. `drupal/project_browser`. - * @param string $url - * URL of the project. + * @param \Drupal\Core\Url|null $url + * URL of the project, if any. Defaults to NULL. * @param array $categories * Value of module_categories of the project. * @param array $images @@ -127,7 +127,7 @@ class Project implements \JsonSerializable { public int $created, public array $author, public string $packageName, - public string $url = '', + public ?Url $url = NULL, public array $categories = [], public array $images = [], public array $warnings = [], @@ -212,7 +212,7 @@ class Project implements \JsonSerializable { 'is_maintained' => $this->isMaintained, 'is_active' => $this->isActive, 'flag_project_star_user_count' => $this->starUserCount, - 'url' => $this->url, + 'url' => $this->url?->setAbsolute()->toString(), 'status' => match ($this->status) { ActivationStatus::Absent => 'absent', ActivationStatus::Present => 'present', diff --git a/sveltejs/public/build/bundle.js b/sveltejs/public/build/bundle.js index 9dfa1203c6e12615d72bcf461050b11fc8986a19..230921d72d367d2edf7b650eabf5b13db7f1b4a0 100644 Binary files a/sveltejs/public/build/bundle.js and b/sveltejs/public/build/bundle.js differ diff --git a/sveltejs/public/build/bundle.js.map b/sveltejs/public/build/bundle.js.map index 33da41c1c1fd4a09783e304e57d2941e11bded0f..a34b7d491f514d2bc8c77cd2e97957fbaa335234 100644 Binary files a/sveltejs/public/build/bundle.js.map and b/sveltejs/public/build/bundle.js.map differ diff --git a/sveltejs/src/ModulePage.svelte b/sveltejs/src/ModulePage.svelte index 6b095844f73803747d90e9ae090ef378a3130a9e..56ed9295103ecbf264a26be0cda87b158a3afe15 100644 --- a/sveltejs/src/ModulePage.svelte +++ b/sveltejs/src/ModulePage.svelte @@ -115,17 +115,6 @@ </div> {/if} - {#if project.project_machine_name} - <div - class="pb-module-page__view-commands pb-module-page__sidebar_element" - > - <button - class="project__action_button" - onclick="window.location.href='https://drupal.org/project/{project.project_machine_name}';" - >View on Drupal.org</button - > - </div> - {/if} {#if project.url} <div class="pb-module-page__view-commands pb-module-page__sidebar_element" @@ -133,7 +122,7 @@ <button class="project__action_button" onclick="window.location.href='{project.url}';" - >View on Drupal.org</button + >{Drupal.t('Learn more')}</button > </div> {/if} diff --git a/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php b/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php index 712022a82740e3b62a7f52fb51ced20c390d4dba..c048b4d1a8112eefc7adf6f79c7687d118c470f4 100644 --- a/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php +++ b/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php @@ -8,6 +8,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\Url; use Drupal\project_browser\DevelopmentStatus; use Drupal\project_browser\MaintenanceStatus; use Drupal\project_browser\Plugin\ProjectBrowserSourceBase; @@ -421,7 +422,7 @@ class ProjectBrowserTestMock extends ProjectBrowserSourceBase { created: $project_data['created'], author: ['name' => $project_data['author']], packageName: 'drupal/' . $project_data['field_project_machine_name'], - url: 'https://www.drupal.org/project/' . $project_data['field_project_machine_name'], + url: Url::fromUri('https://www.drupal.org/project/' . $project_data['field_project_machine_name']), // Add name property to each category, so it can be rendered. categories: array_map(fn($category) => $categories[$category['id']] ?? '', $project_data['project_data']['taxonomy_vocabulary_3'] ?? []), images: $project_data['project_data']['field_project_images'] ?? [],