Only add in the additional metadata if we are also adding them to the form
[civicrm-core.git] / CRM / Core / Module.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 * A module is any software package that participates in the hook
14 * system, such as CiviCRM Module-Extension, a Drupal Module, or
15 * a Joomla Plugin.
16 *
17 * @package CRM
ca5cec67 18 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
19 */
20class CRM_Core_Module {
21
22 /**
23 * @var string
24 */
25 public $name;
26
27 /**
e97c66ff 28 * Is the module enabled.
29 *
30 * @var bool
6a488035
TO
31 */
32 public $is_active;
33
a0ee3941 34 /**
e97c66ff 35 * Class constructor.
36 *
100fef9d 37 * @param string $name
e97c66ff 38 * @param bool $is_active
a0ee3941 39 */
6a488035
TO
40 public function __construct($name, $is_active) {
41 $this->name = $name;
42 $this->is_active = $is_active;
43 }
44
45 /**
d09edf64 46 * Get a list of all known modules.
3bdf1f3a 47 *
48 * @param bool $fresh
49 * Force new results?
50 *
51 * @return array
6a488035
TO
52 */
53 public static function getAll($fresh = FALSE) {
54 static $result;
55 if ($fresh || !is_array($result)) {
56 $result = CRM_Extension_System::singleton()->getMapper()->getModules();
518fa0ee
SL
57 // pseudo-module for core
58 $result[] = new CRM_Core_Module('civicrm', TRUE);
6a488035
TO
59
60 $config = CRM_Core_Config::singleton();
66e42142 61 $result = array_merge($result, $config->userSystem->getModules());
6a488035
TO
62 }
63 return $result;
64 }
96025800 65
5bbcc823
TO
66 /**
67 * Get the status for each module.
68 *
69 * @param array $modules
70 * Array(CRM_Core_Module).
71 * @return array
72 * Array(string $moduleName => string $statusCode).
73 * @see CRM_Extension_Manager::STATUS_INSTALLED
74 * @see CRM_Extension_Manager::STATUS_DISABLED
75 */
76 public static function collectStatuses($modules) {
be2fb01f 77 $statuses = [];
5bbcc823
TO
78 foreach ($modules as $module) {
79 $statuses[$module->name] = $module->is_active ? CRM_Extension_Manager::STATUS_INSTALLED : CRM_Extension_Manager::STATUS_DISABLED;
80
81 }
82 return $statuses;
83 }
84
6a488035 85}