Images do not display in Layout Builder if Social File Private enabled

Created on 20 April 2021, about 4 years ago
Updated 16 May 2025, 3 days ago

Problem/Motivation

Uploading an image in Layout Builder does not show the image.

This may be the same thing as Enabling private files breaks your site β†’ .

Steps to reproduce

I've created a content type called Outside Page intended to be used with a custom theme that is outside of the OS universe. I've enabled Layout Builder. When I edit a Layout Builder section with CKEditor and upload an image, the file goes to the private file system.

For an "inside page," this is correct behavior if the node is part of a group and the image must remain protected by the private file system. However, for an "outside page," the result is that the image doesn't appear to an anonymous user.

Proposed resolution

Some code for further explanation:

This file identifies the basic and full editor text formats as some that should be private.

profiles/contrib/social/modules/custom/social_file_private/src/SocialFilePrivateTextEditorConfigOverride.php:

  public function getTextEditorsToProtect() {
    $config_names = [
      'editor.editor.basic_html',
      'editor.editor.full_html',
    ];
    return $config_names;

Because $names comes across as editor.editor.full_html, it matches the array and the location is set to private.

  public function loadOverrides($names) {
    $overrides = [];
    if (PrivateStream::basePath()) {
      $config_names = $this->getTextEditorsToProtect();
      foreach ($config_names as $config_name) {
        if (in_array($config_name, $names)) {
          $scheme = $this->configFactory
            ->getEditable($config_name)
            ->get('image_upload.scheme');
          if ($scheme == 'public') {
            $overrides[$config_name]['image_upload']['scheme'] = 'private';

Workaround

One way to get around this is to create a new text format, such as "Full HTML (outside)", that will not get caught by the logic above. This seems to be working for me.

Remaining tasks

It seems that two things need to happen:

  • update the documentation β†’ to explain why this happens and the workaround
  • figure out a long-term solution in which image uploads "know" when they are and are not to be protected; perhaps the workaround is the best solution and perhaps not
πŸ› Bug report
Status

Closed: outdated

Version

10.0

Component

Code (back-end)

Created by

πŸ‡ΊπŸ‡ΈUnited States aangel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024