Glazed Builder 1.4.2 breaks image links

Glazed Builder 1.4.2 breaks image URLs. You will see this when you add an image to a Drag and Drop page that is deeper than the root folder. Because the image URL is missing an initial /, pages directly off the root work. Deeper than that, images don’t show up (because the image URL becomes relative to the current path). Glazed Builder 1.4.0 does not have this issue.

Solution

Here’s a fix. 

In profiles/cms/modules/sooperthemes_premium/glazed_builder/src/Service/GlazedBuilderService.php, copy the setters for filesDirectoryPath and modulePath from insertBaseTokens() to replaceBaseTokens().

Like so:

  public function replaceBaseTokens(&$content) {
    // Get url-safe path, replace backslashes from windows paths

    // this is the old way from v1.4.0
    //$filesDirectoryPath = str_replace('\\', '/', $this->getFilesDirectoryPath());
    //$modulePath = str_replace('\\', '/', $this->getModulePath());

    // this is how they are set in v1.4.2
    $filesDirectoryPath = file_url_transform_relative(file_create_url($this->getFilesDirectoryPath()));
    $modulePath = file_url_transform_relative(file_create_url($this->getModulePath()));

    [...]

  }

The way the paths are set changed between 1.4.0 and 1.4.2. However, the change didn’t make it into the replaceBaseTokens() method in 1.4.2. It’s just in insertBaseToken(). Make the two methods parallel and the missing image issue goes away.

This discrepancy was revealed by comparing the glazed_builder folders for version 1.4.0 and 1.4.2 with

git diff --no-index folderA folderB

It just happens that I don’t have version 1.4.1 so I couldn’t include it in the comparison.