Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • documentation/docs/dev
  • totten/dev
  • bgm/dev
  • ivan_compucorp/dev
  • seamuslee/dev
  • artfulrobot/dev
  • ufundo/dev
  • wmortada/dev
  • lucky091588/dev
  • DaveD/dev
  • jtwyman/dev
  • rukkykofi/dev
  • JonGold/dev
  • jaapjansma/developer-docs
  • alainb/dev
  • noah/dev
  • justinfreeman/dev
  • pradeep/dev
  • larssg/dev
  • eileen/dev
  • darrick/dev
  • mattwire/dev
  • colemanw/dev
  • homotechsual/dev
  • JoeMurray/dev
  • maynardsmith/dev
  • kurund/dev
  • rocxa/dev
  • AllenShaw/dev
  • bradleyt/dev
  • chrisgaraffa/dev
  • martin.w/dev
  • herbdool/dev
  • MattTrim1/dev
  • Detlev/dev
  • ErikHommel/dev
  • brienne/devdocs
  • pminf/dev
  • SarahFG/dev
  • ayduns/dev
  • JKingsnorth/dev
  • ginkgomzd/dev
  • nicol/dev
  • almeidam/dev
  • arthurm/dev
  • damilare/dev
  • semseysandor/dev
  • major/devdocs
  • usha.makoa/dev
  • yurg/dev
  • shaneonabike/dev
  • andie/dev
  • mmyriam/dev
  • gngn/dev
  • florian-dieckmann/dev
  • jade/dev
  • luke.stewart/dev
  • vinaygawade/dev
58 results
Show changes
Showing
with 1350 additions and 437 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Extension Structure
## Extension Files
The [civix](/extensions/civix.md) command line tool will generate the following structure
The [civix](civix.md) command line tool will generate the following structure
for you:
- ***info.xml*** is a manifest that describes your extension – the name, license, version number, etc. You should edit most information in this file. The information contained in this file will also be used if published on civicrm.org.
- ***myextension.php*** stores source code for all your hooks. It includes a few default hook implementations which will make development easier. You can add and remove hooks as you wish. (Note: This file name is different in each module – it is based the module's *[short-name](/extensions/index.md#extension-names)*.)
- ***myextension.php*** stores source code for all your hooks. It includes a few default hook implementations which will make development easier. You can add and remove hooks as you wish. (Note: This file name is different in each module – it is based the module's *[short-name](index.md#extension-names)*.)
- ***myextension.civix.php*** contains auto-generated helper functions. These deal with common problems like registering your
module in the template include-path. `civix` may automatically overwrite this file, so generally do not edit it.
## Extension Directory Structure
In addition, civix creates some empty directories. These directories are reminiscent of the directory structure in CiviCRM core:
- ***CRM/Myextension/*** stores PHP class files. Classes in this folder should be prefixed with "CRM\_Myextension\_".
- ***templates/*** stores Smarty templates.
- ***xml/*** stores XML configuration files (such as URL routes and schema xml).
- ***build/*** stores exportable .zip files.
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\BAO\", 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.
Each extension has the one or or more of the following directories. Those are not necessarily needed and most of them are generated when using `civix generate:module`.
These directories are similar to the directory structure of CiviCRM core.
- ***Civi/*** Contains the [PSR4](https://www.php-fig.org/psr/psr-4/) autoloaded classes for the namespace "Civi".
- ***CRM/Myextension/*** stores PHP class files. Classes in this folder should be prefixed with "CRM\_Myextension\_".
- ***schema/*** stores entity declarations in the form of `.entityType.php` files.
- ***templates/*** stores Smarty templates.
- ***xml/*** stores XML configuration files (such as URL routes).
- ***build/*** stores exportable .zip files.
- ***api/*** (*deprecated*) location for api v3 files.
- ***mixin/*** contains [mixin](../framework/mixin/index.md) files generated by Civix.
- ***managed/*** contains managed entity declarations.
- ***sql/*** when your extension provides custom entities or custom database tables this directory contains the SQL file to install and uninstall the extension.
- ***ang/*** location for Afforms or custom AngularJS code.
- ***form-processors/*** when your extension provides [form processors](https://civicrm.org/extensions/form-processor) this is the directory containing the form processors
- ***data-processors/*** when your extension provides [data processors](https://civicrm.org/extensions/data-processor) this is the directory containing the data processors
- ***searchactions/*** when your extension provides search actions from the [search action designer](https://civicrm.org/extensions/search-action-designer) this is the directory containing the search actions.
- ***tests/*** when your extension provides units tests those are stored in this directory.
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\BAO\", 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.
Also, if you want the classes in ***CRM/Myextension/*** folder to be autoloaded, make sure to follow [PSR0](https://www.php-fig.org/psr/psr-0/) conventions: i.e. CRM_Myextension_Myfolder_MyClass corresponds to file CRM/Myextension/Myfolder/MyClass.php. If you don't you'll have to manually include/require your class files.
## The Big `E`
......@@ -28,13 +42,13 @@ For example, this code displays a translated message (using the translation data
```php
if ($welcoming) {
CRM_Core_Session::setStatus(ts('Hello world!', array(
CRM_Core_Session::setStatus(ts('Hello world!', [
'domain' => 'org.civicrm.myextension',
)));
]));
} else {
CRM_Core_Session::setStatus(ts('Goodbye cruel world!', array(
CRM_Core_Session::setStatus(ts('Goodbye cruel world!', [
'domain' => 'org.civicrm.myextension',
)));
]));
}
```
......@@ -54,7 +68,7 @@ if ($welcoming) {
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::ts($text)` -- Translate a string (using the extension's 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)
......
# Troubleshooting
If you are struggling, the best thing to do is reach out to the [CiviCRM community](/basics/community.md).
If you are struggling, the best thing to do is reach out to the [CiviCRM community](../basics/community.md).
If you cannot find the answer in this guide or by searching in the [CiviCRM StackExchange site](http://civicrm.stackexchange.com/) then please [ask](http://civicrm.stackexchange.com/questions/ask). Asking questions on StackExchange not only helps you but may well help others who follow you.
......@@ -22,7 +22,7 @@ A: You might have missed the step about setting 'civicrm\_api3\_conf\_path' ([ht
Q: I've tried to generate a page/report/search/upgrader/etc with civix but it's not working.
A: For all of the various types, you must first run [generate:module](http://generatemodule), and then \`cd\` into the folder (e.g. com.example.myextension) before running one of the other \`generate:\` commands.
A: For all of the various types, you must first run [generate:module](civix.md#generate-module), and then \`cd\` into the folder (e.g. com.example.myextension) before running one of the other \`generate:\` commands.
## Out-of-date templates
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.