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
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
9a8e8451
Commit
9a8e8451
authored
7 years ago
by
totten
Browse files
Options
Downloads
Patches
Plain Diff
extensions/structure - Document the big E
parent
eba54978
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/extensions/structure.md
+47
-0
47 additions, 0 deletions
docs/extensions/structure.md
with
47 additions
and
0 deletions
docs/extensions/structure.md
+
47
−
0
View file @
9a8e8451
...
...
@@ -31,3 +31,50 @@ reminiscent of the directory structure in CiviCRM core:
When adding files into these directories it is advisable to follow similar patterns to that in CiviCRM Core
e.g. BAO files should go in "CRM
\_
Myextension
\B
AO
\"
, likewise with Form and Page. This ensures that for developers
that seek to modify or improve the extension files can be found in standard locations.
## The Big `E`
There are many times when you need to reference something from the
extension -- e.g. its name, its file-path, or its translated messages.
For example, this code displays a translated message (using the translation
data for this extension):
```
php
if
(
$welcoming
)
{
CRM_Core_Session
::
setStatus
(
ts
(
'Hello world!'
,
array
(
'domain'
=>
'org.civicrm.myextension'
,
)));
}
else
{
CRM_Core_Session
::
setStatus
(
ts
(
'Goodbye cruel world!'
,
array
(
'domain'
=>
'org.civicrm.myextension'
,
)));
}
```
Repeatedly entering the name of the extension is a bit tiresome.
For code generated by
`civix`
v17.08.0+ (or suitably
[
upgraded
](
https://github.com/totten/civix/blob/master/UPGRADE.md
)
),
`civix`
includes the
`E`
helper which provides easier access:
```
php
use
CRM_Mymodule_ExtensionUtil
as
E
;
if
(
$welcoming
)
{
CRM_Core_Session
::
setStatus
(
E
::
ts
(
'Hello world!'
));
}
else
{
CRM_Core_Session
::
setStatus
(
E
::
ts
(
'Goodbye cruel world!'
));
}
```
Note that
`E`
is an alias. It stands for "extension" -- as in "the current
extension that I'm writing". It's a very thin class that provides small
helpers for looking up your extension's resources, e.g.
*
`E::ts($text)`
-- Translate a string (using the extensions' translation file)
*
`E::path($file)`
-- Get the path to a resource file (within this extension)
*
`E::url($file)`
-- Get the URL to a resource file (within this extension)
*
`E::findClass($suffix)`
-- Get the full name of a class (within this extension)
*
`E::LONG_NAME`
-- The full length key for this extension (eg
`org.example.myextension`
)
*
`E::SHORT_NAME`
-- The abbreviated key for this extension (eg
`myextension`
)
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