layout_paragraphs_admin library loads in frontend (if logged in)

Created on 30 January 2024, 8 months ago

Problem/Motivation

This should be loaded only on layout paragraphs forms, otherwise this will cause serious issues to the frontend styles, if logged in:

/**
 * Implements hook_library_info_alter().
 */
function drowl_layouts_library_info_alter(&$libraries, $extension) {
  if ($extension !== 'drowl_layouts') {
    return;
  }

  // Allow default theme to add drowl_layouts_layout_paragraphs_additions library:
  if(isset($libraries['layout_paragraphs_admin'])){
    // Add additional library from the current default theme,
    // if existing ('THEMENAME/drowl_layouts_layout_paragraphs_additions'),
    // see README:
    $default_theme = \Drupal::config('system.theme')->get('default');
    if (!empty($default_theme)) {
      $layout_paragraphs_theme_addition_library = \Drupal::service('library.discovery')->getLibraryByName($default_theme, 'drowl_layouts_layout_paragraphs_additions');
      if (!empty($layout_paragraphs_theme_addition_library)) {
        $libraries['layout_paragraphs_admin']['dependencies'][] = $default_theme . '/drowl_layouts_layout_paragraphs_additions';
      }
    }
  }
}

Basically the conditions are the same as in:

/**
 * Implements hook_layout_builder_overrides_entity_form_display_alter().
 */
function drowl_layouts_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // Add drowl_layouts/admin library for layout_builder:
  if (in_array($form_id, [
    'entity_view_display_layout_builder_form',
    'layout_builder_configure_section',
  ])) {
    // Add our library for the backend on the outside-in container:
    $form['#attached']['library'][] = 'drowl_layouts/admin';
  }
}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: cannot reproduce

Version

4.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @thomas.frobieter
  • Okay, got it. The drowl_paragraphs/admin library is not (only) loaded by drowl_layouts, it's loaded by drowl_paragraphs:

    function drowl_paragraphs_preprocess_paragraph(&$variables) {
      // Add frontend library for paragraphs display:
      $variables['#attached']['library'][] = 'drowl_paragraphs/global';
    
      // Add backend library if paragraph is in preview view mode.
      if (!empty($variables['view_mode']) && $variables['view_mode'] == 'preview') {
        $variables['#attached']['library'][] = 'drowl_paragraphs/admin';
      }
    }
    

    This is 100% correct. We attach it to the paragraph, if the view_mode is 'preview'.

    In this specific case, the layout_builder page is overridden, while the paragraphs field is set to view_mode 'default'. So this is also correct. I consider a layout_builder bug.

  • 🇩🇪Germany Anybody Porta Westfalica

    @thomas.frobieter: Found it! Isn't a bug in any module, but a misconfiguration on that page:

    /admin/structure/paragraphs_type/container_tabs_accordion/display

    "Preview" view mode was selected for the tabs reference!

  • Status changed to Closed: cannot reproduce 8 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.71.5 2024