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

Give the custom css file a 'name' to make it easier to manipulate in hook_civicrm_alterBundle() #20278

Merged
merged 1 commit into from
May 19, 2021

Conversation

aydun
Copy link
Contributor

@aydun aydun commented May 12, 2021

Overview

Give the custom CSS file a useful 'name' to make it easier to manipulate in the alterBundle hook.

Before

In the resources bundle, the custom CSS snippet has a 'name' attribute the same as the path - something like http://example.org/sites/default/files/civicrm/css/custom.css?r=sdEtX

After

In the resources bundle, the custom CSS snippet has a 'name' attribute of 'civicrm:css/custom.css'. This enables implementations of hook_civicrm_alterBundle() to target the custom css file reliably.

Technical Details

Nothing

Comments

This should not result in any changes other than implementations of hook_civicrm_alterBundle()
Has a test.

@civibot
Copy link

civibot bot commented May 12, 2021

(Standard links)

@civibot civibot bot added the master label May 12, 2021
$this->assertEquals('civicrm:css/custom.css', $bundle->get('civicrm:css/custom.css')['name']);
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The styleChecker wants you to take out this extra line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - removed.

@aydun aydun force-pushed the name_custom_css branch from 6b29fe3 to 996f54f Compare May 12, 2021 20:57
@colemanw
Copy link
Member

A+ for including a test :)

@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label May 12, 2021
aydun added a commit to aydun/finsburypark that referenced this pull request May 12, 2021
This means custom CSS also needs to be bumped above 290.

Until civicrm/civicrm-core#20278 is merged,
there is no easy way to identify which snippet is the custom CSS one so
we search for 'custom.css' in the name.
@totten
Copy link
Member

totten commented May 13, 2021

This looks like a good idea.

Theoretically, sometimes one might be concerned that adding a name might change things if someone had targeted before... but it's really hard to see how anyone would have sensibly targeted the old/implicit name before. This patch does makes it more sensible. So +1.

@seamuslee001
Copy link
Contributor

ping @haystack @mattwire @jamienovick as you might be interested in this change

@jamienovick
Copy link

@deb1990 any views on this?

@@ -97,7 +97,7 @@ public static function createStyleBundle($name) {
$config = CRM_Core_Config::singleton();
if (!empty($config->customCSSURL)) {
$customCSSURL = Civi::resources()->addCacheCode($config->customCSSURL);
$bundle->addStyleUrl($customCSSURL, 99);
$bundle->addStyleUrl($customCSSURL, ['weight' => 99, 'name' => 'civicrm:css/custom.css']);
Copy link
Contributor

@deb1990 deb1990 May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a very good idea. A small suggestion though.
Do we need the :css thingy? How about just making it civicrm:custom.css.
Its not a huge deal, but civicrm:css/custom.css kind of makes it looks like a URL. When civicrm:custom.css looks more of an identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes ... what's in a name??

Resources added via addStyleFile() have a default name combining the extension name and the relative path so the other resources added by createStyleBundle() are civicrm:css/civicrm.css and civicrm:css/crm-i.css. So following that pattern of names I went with civicrm:css/custom.css. However,

  1. the file isn't provided by core so arguably isn't civicrm - but it is added by core.
  2. the path is not necessarily css - but is quite likely to be [civicrm.files]/css
  3. the file name is not necessarily custom.css- but is a common option

Providing the name is unique I don't think it matters much. The purpose is to let people target that custom css file, whatever it's actual filename or path. I did consider civicrm:custom.css but thought the omission of the css/ part might cause more question since the name then does not follow the pattern of the other names in the bundle.

Happy to change the name if there's consensus on a better one.

And while you're all thinking about this, perhaps you could also comment on https://lab.civicrm.org/dev/core/-/issues/2460 which led to this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. It makes sense, no need to change in that case.

@eileenmcnaughton
Copy link
Contributor

This just went out in the dev digest - it can be merged in a day or 2

@seamuslee001
Copy link
Contributor

Merging as per @eileenmcnaughton 's comment

@seamuslee001 seamuslee001 merged commit 5fc9bd4 into civicrm:master May 19, 2021
@aydun
Copy link
Contributor Author

aydun commented May 20, 2021

Thanks all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants