Move makePathRelative from SDC to the FileSystem component

Created on 7 April 2023, over 1 year ago
Updated 20 April 2023, over 1 year ago

Problem/Motivation

The functionality in Drupal\sdc\Utilities::makePathRelative is not specific to SDC. It was introduced to fit a particular need, but it fits better in the FileSystem component.

Proposed resolution

Since we cannot change core to serve an experimental module, we are deferring this to when ✨ Add Single Directory Components as a new experimental module Fixed is merged and we are working towards stabilization of SDC in 🌱 Single Directory Components module roadmap: the path to beta and stable Active

πŸ“Œ Task
Status

Closed: won't fix

Version

10.1 ✨

Component
File systemΒ  β†’

Last updated 1 day ago

Created by

e0ipso Can Picafort

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

  • Issue created by @e0ipso
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Blocker is in. Also moving to β€œfile system” since that seems more appropriate.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Looking at core/modules/sdc from the latest 10.1.x branch and grep'ing for makePathRelative, I now find:

    ./src/ComponentPluginManager.php:        $altered_filename = $this->makePathRelativeToLibraryRoot($absolute_filename);
    ./src/ComponentPluginManager.php:      $altered_filename = $this->makePathRelativeToLibraryRoot($absolute_filename);
    ./src/ComponentPluginManager.php:      ? $this->makePathRelativeToLibraryRoot($absolute_path)
    ./src/ComponentPluginManager.php:  private function makePathRelativeToLibraryRoot(string $path): string {
    

    Looking at the implementation:

      private function makePathRelativeToLibraryRoot(string $path): string {
        $library_provider_root = $this->moduleHandler
          ->getModule('sdc')
          ->getPath();
        $num_dots = count(
          array_filter(explode(DIRECTORY_SEPARATOR, $library_provider_root))
        );
        $dots = str_repeat('../', $num_dots);
        $path_from_root = str_starts_with($path, $this->appRoot)
          ? substr($path, strlen($this->appRoot) + 1)
          : $path;
        return $dots . $path_from_root;
      }
    

    That seems kinda whacky and specific. πŸ˜‰ Not sure we want to move this to the FileSystem component anywhere. πŸ˜…

    @e0ipso: Can you re-confirm you think this is a good idea, and if so, update the summary to reflect the current state of the code and where you propose to move this private helper to?

    Thanks!
    -Derek

  • Status changed to Closed: won't fix over 1 year ago
  • e0ipso Can Picafort

    @dww thanks for catching this. Indeed, the code changed significantly after I created this follow up. Before it was more generic, and it might have made sense. However @alexpott pointed out we didn't need to make it generic since we already have Symfony's FileSystem::makePathRelative available. That's when we decided to make it specific.

    Closing as won't fix.

Production build 0.71.5 2024