/**
  * WARNING: This interface may change.
  *
  * This provides information about the setting - similar to the fields concept for DAO information.
  * As the setting is serialized code creating validation setting input needs to know the data type
  * This also helps move information out of the form layer into the data layer where people can interact with
  * it via the API or other mechanisms. In order to keep this consistent it is important the form layer
  * also leverages it.
  *
  * Note that this function should never be called when using the runtime getvalue function. Caching works
  * around the expectation it will be called during setting administration
  *
  * Function is intended for configuration rather than runtime access to settings
  *
  * The following params will filter the result. If none are passed all settings will be returns
  *
  * @param array $filters
  * @param int $domainID
  *
  * @return array
  *   the following information as appropriate for each setting
  *   - name
  *   - type
  *   - default
  *   - add (CiviCRM version added)
  *   - is_domain
  *   - is_contact
  *   - description
  *   - help_text
  */
 public static function getMetadata($filters = array(), $domainID = NULL)
 {
     if ($domainID === NULL) {
         $domainID = \CRM_Core_Config::domainID();
     }
     $cache = \Civi::cache('settings');
     $cacheString = 'settingsMetadata_' . $domainID . '_';
     // the caching into 'All' seems to be a duplicate of caching to
     // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
     $settingsMetadata = $cache->get($cacheString);
     $cached = is_array($settingsMetadata);
     if (!$cached) {
         $settingsMetadata = $cache->get(self::ALL);
         if (empty($settingsMetadata)) {
             global $civicrm_root;
             $metaDataFolders = array($civicrm_root . '/settings');
             \CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
             $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
             $cache->set(self::ALL, $settingsMetadata);
         }
     }
     \CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL);
     if (!$cached) {
         $cache->set($cacheString, $settingsMetadata);
     }
     self::_filterSettingsSpecification($filters, $settingsMetadata);
     return $settingsMetadata;
 }
Example #2
0
 /**
  * This provides information about the setting - similar to the fields concept for DAO information.
  * As the setting is serialized code creating validation setting input needs to know the data type
  * This also helps move information out of the form layer into the data layer where people can interact with
  * it via the API or other mechanisms. In order to keep this consistent it is important the form layer
  * also leverages it.
  *
  * Note that this function should never be called when using the runtime getvalue function. Caching works
  * around the expectation it will be called during setting administration
  *
  * Function is intended for configuration rather than runtime access to settings
  *
  * The following params will filter the result. If none are passed all settings will be returns
  *
  * @param int $componentID
  *   Id of relevant component.
  * @param array $filters
  * @param int $domainID
  * @param null $profile
  *
  * @return array
  *   the following information as appropriate for each setting
  *   - name
  *   - type
  *   - default
  *   - add (CiviCRM version added)
  *   - is_domain
  *   - is_contact
  *   - description
  *   - help_text
  */
 public static function getSettingSpecification($componentID = NULL, $filters = array(), $domainID = NULL, $profile = NULL)
 {
     $cacheString = 'settingsMetadata_' . $domainID . '_' . $profile;
     foreach ($filters as $filterField => $filterString) {
         $cacheString .= "_{$filterField}_{$filterString}";
     }
     $cached = 1;
     // the caching into 'All' seems to be a duplicate of caching to
     // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
     $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Specs', $cacheString, $componentID);
     if ($settingsMetadata === NULL) {
         $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID);
         if (empty($settingsMetadata)) {
             global $civicrm_root;
             $metaDataFolders = array($civicrm_root . '/settings');
             CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
             $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
             CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Spec', 'All', $componentID);
         }
         $cached = 0;
     }
     CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, $profile);
     self::_filterSettingsSpecification($filters, $settingsMetadata);
     if (!$cached) {
         // this is a bit 'heavy' if you are using hooks but this function
         // is expected to only be called during setting administration
         // it should not be called by 'getvalue' or 'getitem
         CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Specs', $cacheString, $componentID);
     }
     return $settingsMetadata;
 }