In past versions of Panel layouts I have always used admin css feature. This was required as I need to provide a custom CSS file only in the admin section. This custom CSS file must not used in the public theme as the content of this CSS is already included in the CSS framework I'm using and would duplicate the CSS code otherwise.

As it looks missing in the module, can you add this back or explain me how to archive the old behaviour, please?

Comments

hass created an issue. See original summary.

hass’s picture

Do you know where can I find the preview of the content blocks in D8 Panels? I can assign blocks to regions, but cannot preview it as in past.

dsnopek’s picture

I've never actually used the 'admin css' feature in Panels in D7, but assuming I'm understanding it right, it is a CSS file to only load when you're in the Page Manager UI editing a Panels variant that uses that layout, right?

If that's the case, I'm not sure that that feature makes sense in layout_plugin. Since layout_plugin is used by both Panels and Display Suite (and could be used by any contrib module in the future), there's really no knowing what the admin UI will be like.

If you really need your layout to use different CSS when used in the admin theme, it'd probably be best to override the layout stylesheet in your admin theme! Using normal theming mechanisms, you can make it so that a different CSS file is loaded when in a particular theme.

Would that solve your problem?

Do you know where can I find the preview of the content blocks in D8 Panels? I can assign blocks to regions, but cannot preview it as in past.

This functionality hasn't been implemented in Panels yet. Please open an issue in the Panels queue! :-)

hass’s picture

That is not correct. This feature exists in panels D7 and D8, but has not yet converted to D8. See http://cgit.drupalcode.org/panels/tree/plugins/layouts/flexible/flexible... this becomes a blocker for panels, too.

dsnopek’s picture

Ok, sorry! If my understanding of how 'admin css' works in D7 is incorrect, can you please explain how it actually works?

hass’s picture

assuming I'm understanding it right, it is a CSS file to only load when you're in the Page Manager UI editing a Panels variant that uses that layout, right?

Yes, i think so. It styles the blocks/boxes like the real site. If not loaded you have no idea how the layout looks like and elements can float unconditionally in the admin ui or are completly misaligned.

DamienMcKenna’s picture

It seems like this is a chicken-and-egg problem between the layout's CSS, the front end theme and the admin theme? Maybe the simplest solution would be to make sure the layout's CSS is very barebones and then override the layout's classes in the admin subtheme to adjust it as needed?

dsnopek’s picture

I think the bottom line here is if the core version of layout plugin doesn't have an 'admin css', then then contrib version shouldn't either, otherwise we're introducing a feature and deprecating it at the same time

hass’s picture

I'm not sure what you mean with chicken egg problem. Is it really understood? Just to be safe I give one more example.

My frontend theme is bootstrap, admin theme is seven. Bootstrap has no extra css file for only layouts. If you want a layout you need to fully load the bootstrap framework. No problem in frontend... everything is loaded with the frontend theme.

But can I load full bootstrap framework into seven without any css class conflicts? No! This means I need to write a custom admin css for seven, that shows the layout inside seven without bootstrap. A small css file with just the seven layout code, no bootstrap.

What is here the chicken egg and how should this introducing a feature and deprecating it at the same time??? I do not have an idea how to make wonders happen without admin css.

dsnopek’s picture

... and how should this introducing a feature and deprecating it at the same time???

I can address this part! layout_plugin was merged into core, and so the contrib module will be going away eventually. We're going to try and adopt everything that's in core (per #2854617: Backport all changes from core 8.3) and deprecate everything that isn't in core. If core has no 'admin css' (or equivalent) property, then if we were to introduce it to layout_plugin in contrib, we'd have to deprecate it right away. Any new features should be against core!

DamienMcKenna’s picture

Title: 'admin css' is missing in annotation » Add an 'admin css' option for layouts
Project: Layout Plugin (obsolete, use core's Layout Discovery) » Drupal core
Version: 8.x-1.x-dev » 8.4.x-dev
Component: Code » layout.module
Category: Bug report » Feature request

This is how we handle this, we move it to core as a feature request and it could then be backported to Layout Plugin (if it hasn't been abandoned by then).

The chicken-and-egg issue is related to the layout's CSS. There are multiple admin themes available, just as there are multiple frontend themes available. The layout's CSS should be able to be used no matter where it's used, it should be theme-agnostic. If you don't follow this recommendation then you're going to either have to define requirements / recommendations for the layout ("only suitable for use with Bootstrap-based themes"), otherwise how will you know if the "admin css'" would even work with the admin theme a site is using? What if the site is using a Bootstrap-based admin theme, would the admin CSS file work or would it break? How about using it with an admin theme based on AdaptiveTheme or Omega, or Forty Two, or Adminimal, are you sure the admin CSS would work there too? It really seems like you're talking about a "seven theme css" file rather than a generic "admin css" file.

In short, it's up to you to build up the necessary CSS in the admin theme to work with the layout.

One practical idea would be to include an extra CSS file with any redistributed layouts that's designed for people to add to their theme when they're using the Seven theme, and document in the layout's README.txt file that it should be manually added to the theme, but going beyond that leads to a world of assumptions.

tim.plunkett’s picture

Title: Add an 'admin css' option for layouts » Add an 'admin libraries' option for layouts

CSS cannot be attached directly, a library (*.libraries.yml) must be used instead.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Component: layout.module » layout_discovery.module
dsnopek’s picture

Just re-read through this issue because Tim updated it. :-)

To try and clarify why I think this feature doesn't make sense...

@hass in #9 wrote:

My frontend theme is bootstrap, admin theme is seven. Bootstrap has no extra css file for only layouts. If you want a layout you need to fully load the bootstrap framework. No problem in frontend... everything is loaded with the frontend theme.

But can I load full bootstrap framework into seven without any css class conflicts? No! This means I need to write a custom admin css for seven, that shows the layout inside seven without bootstrap. A small css file with just the seven layout code, no bootstrap.

It makes sense that the layout might need different CSS when used seven. However, how does your layout know that it's going to be used in seven and not another admin theme? The layout only gets a single 'admin library' (since CSS comes from libraries which Tim pointed out in #12), at least that's how it worked in D7. I suppose we could make that property take an associative array where the keys are the particular admin theme, but I'm not sure it makes sense to couple layouts and themes that much. It also opens up some interesting questions, like, if a library is targeting 'seven' do we also load that in children of 'seven' or only exactly 'seven'?

My suggestion in #3 was that you could override the CSS for the particular layout in your admin theme (same as you can override the CSS of any library in a theme). If you admin theme is 'seven' you'd need to make a new child theme to that. But that seems like the cleanest solution: the theme itself knows how to correct the layout's CSS to work in that theme, and the layout can remain super generic.

hass’s picture

However, how does your layout know that it's going to be used in seven and not another admin theme?

We do not target to seven or any other theme. We need to implement a admin CSS that is totally theme independed and only contain the CSS required to show the layout. It must not conflict with other themes or reuse other theme CSS. This could be archived.

If your admin theme is 'seven' you'd need to make a new child theme to that.

Something I absolutly do not like to do. I have no plans to maintain this.

Again - we had this feature before and it worked well. I have no idea why it was removed and now it need to be added back.

tim.plunkett’s picture

This feature never existed in core and will likely never be added.

dsnopek’s picture

We do not target to seven or any other theme. We need to implement a admin CSS that is totally theme independed and only contain the CSS required to show the layout. It must not conflict with other themes or reuse other theme CSS. This could be archived.

Hm. So, then I must be totally misunderstanding the use case for this... If it's not make it work with a particular admin theme, then what is it for? What is in the admin CSS that isn't in the frontend CSS? Can you give a concrete example? Otherwise, I'm just totally lost on what this is meant to accomplish.

hass’s picture

Let‘s give an example. I hope it is clear. You have a complex frontend theme like bootstrap. Tons of classes are inherited from others. Nothing is really modular and loading all css has a size of 300kb. If bootstrap does not get loaded you cannot load bootstrap cards.

If you would load bootstrap 300kb inside seven only to show the layout you need to load 300kb + 200kb admin theme. It will be just *slow*.

Additional the killer issue comes in mind. The bootstrap theme defines 50 classes that the admin theme also defines. Bootstrap get‘s loaded after admin theme an overrides these 50 classes and thereby completly break the admin theme. It becomes totally unusable.

The solution:

If the small part of css needed to show the layout parts can be made independend and prefixed to never conflict with the admin theme and they are just 10kb for the layout preview + 200kb admin theme.

Result:

No css conflicts, 290kb less css. Why does nobody know this feature from past...?

hass’s picture

@tim: if you have a better solution let us know. But a solution, without cloning seven.

dsnopek’s picture

@hass: Is the theme providing the layout? Or is it a module?

The 'radix_layout' module solves pretty much the problem from your example (in both D7 and D8) but without using the 'admin css' feature. What it does is provide the minimal Boostrap grid system CSS necessary to display the themes in the layout's main CSS. And then in the 'radix' theme (which includes all off Bootstrap) it will remove the 'radix_layouts' CSS so it's never added to the page.

The net result is that the 'radix_layouts' layouts will work in any theme, whether that's a different non-bootstrap frontend theme or an admin theme. But then in the 'radix' theme, it knows the CSS is unnecessary (and actually could have different breakpoints in a 'radix' sub-theme, if it customized those) so it's removed.

Would something like that work for your use case?

If you're actually defining the layouts inside the theme, then that gets a lot more weird (theme adding CSS to a layout but then also removing it?) but still possible. I guess I can start see how this would be useful for layouts defined in themes, because they would normally expect the theme CSS to be available. But for layouts in modules, you have to assume that your layout could be used in any theme.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.