backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

Provide a way for site builders to include theme css in paragraphs preview #183

Closed herbdool closed 2 months ago

herbdool commented 3 months ago

If someone is using the paragraphs preview, there is no easy way for most site builders to add some css that will show up when editing content. I tend to have the paragraphs display the content preview. I'm including a separate css stylesheet with the hook_field_widget_form_alter(). The stylesheet can live in the default theme and it will be inserted when editing the node. Looks like:

/**
 * Implements hook_field_widget_form_alter().
 */
function my_module_field_widget_form_alter(&$element, &$form_state, $context) {
  if (empty($context['instance']['entity_type']) || $context['instance']['entity_type'] != 'paragraphs_item') {
    return;
  }
  $theme_default = config_get('system.core', 'theme_default');
  $path = backdrop_get_path('theme', $theme_default);
  backdrop_add_css($path . '/css/paragraphs-style.css');
}

But...it might be nice to allow someone to include a line in the theme.info file like what is done with ckeditor: paragraphs_stylesheets[] = css/paragraphs-style.css.

UPDATE: the PR does provide what CKEditor does. It will only attempt to include a stylesheet if it exists, that is, added with a paragraphs_stylesheets[] entry in the theme .info file.

herbdool commented 3 months ago

@laryn I've got a PR for this. It was fairly easy to implement, borrowing from ckeditor module. The rest is up to the site builder.

Perhaps a section could be put into the wiki if this is accepted.

laryn commented 3 months ago

Nice idea, I like this @herbdool.

herbdool commented 2 months ago

@laryn thanks. And it won't impact anything else. It only includes the css file if the themer included it intentionally.

laryn commented 2 months ago

@herbdool I've merged this.