Commit 9e66d94a authored by Fran Garcia-Linares's avatar Fran Garcia-Linares Committed by Tim Plunkett
Browse files

Issue #3298575 by fjgarlin, srishtiiee: URLs in body for projects are relative...

Issue #3298575 by fjgarlin, srishtiiee: URLs in body for projects are relative in the Mock plugin and creates 404s links and broken images
parent 512dc727
Loading
Loading
Loading
Loading
+21 −0
Changes for src/Plugin/ProjectBrowserSource/MockDrupalDotOrg.php: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\project_browser\Plugin\ProjectBrowserSource;

use Composer\Semver\Semver;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -424,6 +425,7 @@ class MockDrupalDotOrg extends ProjectBrowserSourceBase implements ContainerFact
          $project['project_usage_total'] = 0;
        }

        $project['body'] = $this->relativeToAbsoluteUrls($project['body'], 'https://www.drupal.org');
        $project['flag_project_star_user_count'] = 0;
        $project['is_covered'] = $this->projectIsCovered($project);
        $project['is_active'] = $this->projectIsActive($project);
@@ -858,4 +860,23 @@ class MockDrupalDotOrg extends ProjectBrowserSourceBase implements ContainerFact
    return $warnings;
  }

  /**
   * Convert relative URLs found in the body to absolute URLs.
   *
   * @param array $body
   *   Body array field containing summary and value properties.
   * @param string $base_url
   *   Base URL to prepend to relative links.
   *
   * @return array
   *   Body array with relative URLs converted to absolute ones.
   */
  protected function relativeToAbsoluteUrls(array $body, string $base_url) {
    if (empty($body['value'])) {
      $body['value'] = $body['summary'] ?? '';
    }
    $body['value'] = Html::transformRootRelativeUrlsToAbsolute($body['value'], $base_url);
    return $body;
  }

}