Skip to content

Commit

Permalink
Issue #183: Allow inclusion of theme css for paragraphs preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Jul 12, 2024
1 parent 1a7bfaf commit 72648b6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions paragraphs.field_widget.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ function paragraphs_field_multiple_value_form($field, $instance, $langcode, $ite
}
$field_elements['#attached']['js'][] = backdrop_get_path('module', 'paragraphs') . '/js/paragraphs_actions.js';

// Attach any paragraph specific stylesheets from the default theme.
if ($css = _paragraphs_theme_css()) {
$field_elements['#attached']['css'] = $css;
}

return $field_elements;
}

Expand Down
38 changes: 38 additions & 0 deletions paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -1965,3 +1965,41 @@ function paragraphs_autoload_info() {
'paragraphs_handler_relationship' => 'views/paragraphs_handler_relationship.inc',
);
}

/**
* Retrieves the default theme's Paragraphs stylesheets defined in the .info file.
*
* Themes may specify CSS files for use with Paragraphs by
* including a "paragraphs_stylesheets" key in the theme .info file.
*
* @code
* paragraphs_stylesheets[] = css/paragraphs.css
* @endcode
*
* @param string $theme
* The theme name from which the "paragraphs_stylesheets" property should be
* read in the .info files. This theme and all its parent themes will be
* checked. Defaults to the current front-end theme.
*
* @return array
* An array of all CSS to be added by the theme within the Paragraphs.
*/
function _paragraphs_theme_css($theme = NULL) {
$css = array();
if (!isset($theme)) {
$theme = config_get('system.core', 'theme_default');
}
if ($theme_path = backdrop_get_path('theme', $theme)) {
$info = system_get_info('theme', $theme);
if (isset($info['paragraphs_stylesheets'])) {
$css = $info['paragraphs_stylesheets'];
foreach ($css as $key => $path) {
$css[$key] = $theme_path . '/' . $path;
}
}
if (isset($info['base theme'])) {
$css = array_merge($css, _paragraphs_theme_css($info['base theme']));
}
}
return $css;
}

0 comments on commit 72648b6

Please sign in to comment.