3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This interface defines methods that need to be implemented
14 * for a component to introduce itself to the system.
17 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 abstract class CRM_Core_Component_Info
{
22 * Name of the class (minus component namespace path)
23 * of the component invocation class'es name.
25 const COMPONENT_INVOKE_CLASS
= 'Invoke';
28 * Name of the class (minus component namespace path)
29 * of the component BAO Query class'es name.
31 const COMPONENT_BAO_QUERY_CLASS
= 'BAO_Query';
34 * Name of the class (minus component namespace path)
35 * of the component user dashboard plugin.
37 const COMPONENT_USERDASHBOARD_CLASS
= 'Page_UserDashboard';
40 * Name of the class (minus component namespace path)
41 * of the component tab offered to contact record view.
43 const COMPONENT_TAB_CLASS
= 'Page_Tab';
46 * Name of the class (minus component namespace path)
47 * of the component tab offered to contact record view.
49 const COMPONENT_ADVSEARCHPANE_CLASS
= 'Form_Search_AdvancedSearchPane';
52 * Name of the directory (assumed in component directory)
53 * where xml resources used by this component live.
55 const COMPONENT_XML_RESOURCES
= 'xml';
58 * Name of the directory (assumed in xml resources path)
59 * containing component menu definition XML file names.
61 const COMPONENT_MENU_XML
= 'Menu';
64 * Component settings as key/value pairs.
79 * Name of the component.
80 * @param string $namespace
81 * Namespace prefix for component's files.
82 * @param int $componentID
84 public function __construct($name, $namespace, $componentID) {
86 $this->namespace = $namespace;
87 $this->componentID
= $componentID;
88 $this->info
= $this->getInfo();
89 $this->info
['url'] = $this->getKeyword();
93 * EXPERIMENTAL: Get a list of AngularJS modules
96 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
97 * @see CRM_Utils_Hook::angularModules
99 public function getAngularModules() {
104 * Provides base information about the component.
105 * Needs to be implemented in component's information
109 * collection of required component settings
111 abstract public function getInfo();
114 * Get a list of entities to register via API.
117 * list of entities; same format as CRM_Utils_Hook::managedEntities(&$entities)
118 * @see CRM_Utils_Hook::managedEntities
120 public function getManagedEntities() {
125 * Provides permissions that are unwise for Anonymous Roles to have.
128 * list of permissions
129 * @see CRM_Component_Info::getPermissions
131 public function getAnonymousPermissionWarnings() {
136 * Provides permissions that are used by component.
137 * Needs to be implemented in component's information
140 * NOTE: if using conditionally permission return,
141 * implementation of $getAllUnconditionally is required.
143 * @param bool $getAllUnconditionally
146 * collection of permissions, null if none
148 abstract public function getPermissions($getAllUnconditionally = FALSE);
151 * Determine how many other records refer to a given record.
153 * @param CRM_Core_DAO $dao
154 * The item for which we want a reference count.
156 * each item in the array is an array with keys:
157 * - name: string, eg "sql:civicrm_email:contact_id"
158 * - type: string, eg "sql"
159 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
161 public function getReferenceCounts($dao) {
166 * Provides information about user dashboard element.
167 * offered by this component.
170 * collection of required dashboard settings,
171 * null if no element offered
173 abstract public function getUserDashboardElement();
176 * Provides information about user dashboard element.
177 * offered by this component.
180 * collection of required dashboard settings,
181 * null if no element offered
183 abstract public function registerTab();
186 * Get icon font class representing this component.
190 public function getIcon() {
191 return 'crm-i fa-puzzle-piece';
195 * Provides information about advanced search pane
196 * offered by this component.
199 * collection of required pane settings,
200 * null if no element offered
202 abstract public function registerAdvancedSearchPane();
205 * Provides potential activity types that this
206 * component might want to register in activity history.
207 * Needs to be implemented in component's information
211 * collection of activity types
213 abstract public function getActivityTypes();
216 * Provides information whether given component is currently
217 * marked as enabled in configuration.
220 * true if component is enabled, false if not
222 public function isEnabled() {
223 $config = CRM_Core_Config
::singleton();
224 return in_array($this->info
['name'], $config->enableComponents
, TRUE);
228 * Provides component's invocation object.
231 * component's invocation object
233 public function getInvokeObject() {
234 return $this->_instantiate(self
::COMPONENT_INVOKE_CLASS
);
238 * Provides component's BAO Query object.
241 * component's BAO Query object
243 public function getBAOQueryObject() {
244 return $this->_instantiate(self
::COMPONENT_BAO_QUERY_CLASS
);
248 * Builds advanced search form's component specific pane.
250 * @param CRM_Core_Form $form
252 public function buildAdvancedSearchPaneForm(&$form) {
253 $bao = $this->getBAOQueryObject();
254 $bao->buildSearchForm($form);
258 * Provides component's user dashboard page object.
261 * component's User Dashboard applet object
263 public function getUserDashboardObject() {
264 return $this->_instantiate(self
::COMPONENT_USERDASHBOARD_CLASS
);
268 * Provides component's contact record tab object.
271 * component's contact record tab object
273 public function getTabObject() {
274 return $this->_instantiate(self
::COMPONENT_TAB_CLASS
);
278 * Provides component's advanced search pane's template path.
281 * component's advanced search pane's template path
283 public function getAdvancedSearchPaneTemplatePath() {
284 $fullpath = $this->namespace . '_' . self
::COMPONENT_ADVSEARCHPANE_CLASS
;
285 return str_replace('_', DIRECTORY_SEPARATOR
, $fullpath . '.tpl');
289 * Provides information whether given component uses system wide search.
292 * true if component needs search integration
294 public function usesSearch() {
295 return (bool) $this->info
['search'];
299 * Provides the xml menu files.
302 * array of menu files
304 public function menuFiles() {
305 return CRM_Utils_File
::getFilesByExtension($this->_getMenuXMLPath(), 'xml');
309 * Simple "keyword" getter.
310 * FIXME: It should be protected so the keyword is not
311 * FIXME: accessed from beyond component infrastructure.
316 public function getKeyword() {
317 return $this->keyword
;
321 * Helper for figuring out menu XML file location.
324 * component's element as class instance
326 private function _getMenuXMLPath() {
327 global $civicrm_root;
328 $fullpath = $this->namespace . '_' . self
::COMPONENT_XML_RESOURCES
. '_' . self
::COMPONENT_MENU_XML
;
329 return CRM_Utils_File
::addTrailingSlash($civicrm_root . DIRECTORY_SEPARATOR
. str_replace('_', DIRECTORY_SEPARATOR
, $fullpath));
333 * Helper for instantiating component's elements.
338 * component's element as class instance
340 private function _instantiate($cl) {
341 $className = $this->namespace . '_' . $cl;
342 return new $className();