3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This interface defines methods that need to be implemented
30 * for a component to introduce itself to the system.
33 * @copyright CiviCRM LLC (c) 2004-2019
35 abstract class CRM_Core_Component_Info
{
38 * Name of the class (minus component namespace path)
39 * of the component invocation class'es name.
41 const COMPONENT_INVOKE_CLASS
= 'Invoke';
44 * Name of the class (minus component namespace path)
45 * of the component BAO Query class'es name.
47 const COMPONENT_BAO_QUERY_CLASS
= 'BAO_Query';
50 * Name of the class (minus component namespace path)
51 * of the component user dashboard plugin.
53 const COMPONENT_USERDASHBOARD_CLASS
= 'Page_UserDashboard';
56 * Name of the class (minus component namespace path)
57 * of the component tab offered to contact record view.
59 const COMPONENT_TAB_CLASS
= 'Page_Tab';
62 * Name of the class (minus component namespace path)
63 * of the component tab offered to contact record view.
65 const COMPONENT_ADVSEARCHPANE_CLASS
= 'Form_Search_AdvancedSearchPane';
68 * Name of the directory (assumed in component directory)
69 * where xml resources used by this component live.
71 const COMPONENT_XML_RESOURCES
= 'xml';
74 * Name of the directory (assumed in xml resources path)
75 * containing component menu definition XML file names.
77 const COMPONENT_MENU_XML
= 'Menu';
80 * Component settings as key/value pairs.
95 * Name of the component.
96 * @param string $namespace
97 * Namespace prefix for component's files.
98 * @param int $componentID
100 public function __construct($name, $namespace, $componentID) {
102 $this->namespace = $namespace;
103 $this->componentID
= $componentID;
104 $this->info
= $this->getInfo();
105 $this->info
['url'] = $this->getKeyword();
109 * EXPERIMENTAL: Get a list of AngularJS modules
112 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
113 * @see CRM_Utils_Hook::angularModules
115 public function getAngularModules() {
120 * Provides base information about the component.
121 * Needs to be implemented in component's information
125 * collection of required component settings
127 abstract public function getInfo();
130 * Get a list of entities to register via API.
133 * list of entities; same format as CRM_Utils_Hook::managedEntities(&$entities)
134 * @see CRM_Utils_Hook::managedEntities
136 public function getManagedEntities() {
141 * Provides permissions that are unwise for Anonymous Roles to have.
144 * list of permissions
145 * @see CRM_Component_Info::getPermissions
147 public function getAnonymousPermissionWarnings() {
152 * Provides permissions that are used by component.
153 * Needs to be implemented in component's information
156 * NOTE: if using conditionally permission return,
157 * implementation of $getAllUnconditionally is required.
159 * @param bool $getAllUnconditionally
162 * collection of permissions, null if none
164 abstract public function getPermissions($getAllUnconditionally = FALSE);
167 * Determine how many other records refer to a given record.
169 * @param CRM_Core_DAO $dao
170 * The item for which we want a reference count.
172 * each item in the array is an array with keys:
173 * - name: string, eg "sql:civicrm_email:contact_id"
174 * - type: string, eg "sql"
175 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
177 public function getReferenceCounts($dao) {
182 * Provides information about user dashboard element.
183 * offered by this component.
186 * collection of required dashboard settings,
187 * null if no element offered
189 abstract public function getUserDashboardElement();
192 * Provides information about user dashboard element.
193 * offered by this component.
196 * collection of required dashboard settings,
197 * null if no element offered
199 abstract public function registerTab();
202 * Get icon font class representing this component.
206 public function getIcon() {
207 return 'crm-i fa-puzzle-piece';
211 * Provides information about advanced search pane
212 * offered by this component.
215 * collection of required pane settings,
216 * null if no element offered
218 abstract public function registerAdvancedSearchPane();
221 * Provides potential activity types that this
222 * component might want to register in activity history.
223 * Needs to be implemented in component's information
227 * collection of activity types
229 abstract public function getActivityTypes();
232 * Provides information whether given component is currently
233 * marked as enabled in configuration.
236 * true if component is enabled, false if not
238 public function isEnabled() {
239 $config = CRM_Core_Config
::singleton();
240 if (in_array($this->info
['name'], $config->enableComponents
)) {
247 * Provides component's menu definition object.
250 * component's menu definition object
252 public function getMenuObject() {
253 return $this->_instantiate(self
::COMPONENT_MENU_CLASS
);
257 * Provides component's invocation object.
260 * component's invocation object
262 public function getInvokeObject() {
263 return $this->_instantiate(self
::COMPONENT_INVOKE_CLASS
);
267 * Provides component's BAO Query object.
270 * component's BAO Query object
272 public function getBAOQueryObject() {
273 return $this->_instantiate(self
::COMPONENT_BAO_QUERY_CLASS
);
277 * Builds advanced search form's component specific pane.
279 * @param CRM_Core_Form $form
281 public function buildAdvancedSearchPaneForm(&$form) {
282 $bao = $this->getBAOQueryObject();
283 $bao->buildSearchForm($form);
287 * Provides component's user dashboard page object.
290 * component's User Dashboard applet object
292 public function getUserDashboardObject() {
293 return $this->_instantiate(self
::COMPONENT_USERDASHBOARD_CLASS
);
297 * Provides component's contact record tab object.
300 * component's contact record tab object
302 public function getTabObject() {
303 return $this->_instantiate(self
::COMPONENT_TAB_CLASS
);
307 * Provides component's advanced search pane's template path.
310 * component's advanced search pane's template path
312 public function getAdvancedSearchPaneTemplatePath() {
313 $fullpath = $this->namespace . '_' . self
::COMPONENT_ADVSEARCHPANE_CLASS
;
314 return str_replace('_', DIRECTORY_SEPARATOR
, $fullpath . '.tpl');
318 * Provides information whether given component uses system wide search.
321 * true if component needs search integration
323 public function usesSearch() {
324 return $this->info
['search'] ?
TRUE : FALSE;
328 * Provides the xml menu files.
331 * array of menu files
333 public function menuFiles() {
334 return CRM_Utils_File
::getFilesByExtension($this->_getMenuXMLPath(), 'xml');
338 * Simple "keyword" getter.
339 * FIXME: It should be protected so the keyword is not
340 * FIXME: accessed from beyond component infrastructure.
345 public function getKeyword() {
346 return $this->keyword
;
350 * Helper for figuring out menu XML file location.
353 * component's element as class instance
355 private function _getMenuXMLPath() {
356 global $civicrm_root;
357 $fullpath = $this->namespace . '_' . self
::COMPONENT_XML_RESOURCES
. '_' . self
::COMPONENT_MENU_XML
;
358 return CRM_Utils_File
::addTrailingSlash($civicrm_root . DIRECTORY_SEPARATOR
. str_replace('_', DIRECTORY_SEPARATOR
, $fullpath));
362 * Helper for instantiating component's elements.
367 * component's element as class instance
369 private function _instantiate($cl) {
370 $className = $this->namespace . '_' . $cl;
371 require_once str_replace('_', DIRECTORY_SEPARATOR
, $className) . '.php';
372 return new $className();