Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
herbdool opened this issue Jun 24, 2024 · 4 comments · Fixed by #184
Closed

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

herbdool opened this issue Jun 24, 2024 · 4 comments · Fixed by #184
Labels
enhancement New feature or request has pr Has a PR or branch for testing.

Comments

@herbdool
Copy link
Contributor

herbdool commented Jun 24, 2024

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
Copy link
Contributor Author

@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.

@herbdool herbdool added the has pr Has a PR or branch for testing. label Jun 25, 2024
@laryn
Copy link
Member

laryn commented Jul 4, 2024

Nice idea, I like this @herbdool.

@herbdool
Copy link
Contributor Author

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

@laryn
Copy link
Member

laryn commented Jul 12, 2024

@herbdool I've merged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has pr Has a PR or branch for testing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants