Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
brienne
Developer Documentation
Commits
9dba82e8
Unverified
Commit
9dba82e8
authored
5 years ago
by
Alice Frumin
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
buildAsset requires that the $asset varaible look like a file (containg a . )
parent
d1456ac0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/framework/asset-builder.md
+5
-5
5 additions, 5 deletions
docs/framework/asset-builder.md
with
5 additions
and
5 deletions
docs/framework/asset-builder.md
+
5
−
5
View file @
9dba82e8
...
@@ -176,7 +176,7 @@ In `myextension.php`:
...
@@ -176,7 +176,7 @@ In `myextension.php`:
*/
*/
function
myextension_civicrm_buildAsset
(
$asset
,
$params
,
&
$mimetype
,
&
$content
)
{
function
myextension_civicrm_buildAsset
(
$asset
,
$params
,
&
$mimetype
,
&
$content
)
{
// Check for the asset of interest
// Check for the asset of interest
if
(
$asset
!==
'mycss'
)
return
;
if
(
$asset
!==
'mycss
.css
'
)
return
;
// Find the path to our template css file
// Find the path to our template css file
$path
=
\Civi
::
resources
()
->
getPath
(
'org.example.myextension'
,
'css/my_css_template.css'
);
$path
=
\Civi
::
resources
()
->
getPath
(
'org.example.myextension'
,
'css/my_css_template.css'
);
...
@@ -200,12 +200,12 @@ function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content)
...
@@ -200,12 +200,12 @@ function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content)
Check it is functioning correctly:
Check it is functioning correctly:
```
```
$ cv ev '$x = \Civi::service("asset_builder")->render("mycss"); echo $x["content"];'
$ cv ev '$x = \Civi::service("asset_builder")->render("mycss
.css
"); echo $x["content"];'
```
```
Get the generated URL:
Get the generated URL:
```
```
$ cv ev 'return \Civi::service("asset_builder")->getUrl("mycss");'
$ cv ev 'return \Civi::service("asset_builder")->getUrl("mycss
.css
");'
```
```
Now we can use our newly defined asset in place of a static css file in
`myextension.php`
:
Now we can use our newly defined asset in place of a static css file in
`myextension.php`
:
...
@@ -220,8 +220,8 @@ function myextension_civicrm_coreResourceList(&$list, $region) {
...
@@ -220,8 +220,8 @@ function myextension_civicrm_coreResourceList(&$list, $region) {
// CRM_Core_Resources::singleton()->addStyleFile('org.example.myextension', 'css/my_css.css');
// CRM_Core_Resources::singleton()->addStyleFile('org.example.myextension', 'css/my_css.css');
// replace that with the following:
// replace that with the following:
// use the asset_builder service to get the url of an asset labeled 'mycss'
// use the asset_builder service to get the url of an asset labeled 'mycss
.css
'
$url
=
\Civi
::
service
(
'asset_builder'
)
->
getUrl
(
'mycss'
);
$url
=
\Civi
::
service
(
'asset_builder'
)
->
getUrl
(
'mycss
.css
'
);
// load the processed style on the page
// load the processed style on the page
CRM_Core_Resources
::
singleton
()
->
addStyleUrl
(
$url
);
CRM_Core_Resources
::
singleton
()
->
addStyleUrl
(
$url
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment