Merge pull request #18200 from seamuslee001/5.29
[civicrm-core.git] / CRM / Utils / System / DrupalBase.php
CommitLineData
9977c6f5 1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
9977c6f5 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 |
9977c6f5 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
9977c6f5 11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
9977c6f5 16 */
17
18/**
19 * Drupal specific stuff goes here
20 */
21abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
e0dd98a5
EM
22
23 /**
24 * Does this CMS / UF support a CMS specific logging mechanism?
e0dd98a5 25 * @var bool
6714d8d2 26 * @todo - we should think about offering up logging mechanisms in a way that is also extensible by extensions
e0dd98a5 27 */
6714d8d2 28 public $supports_UF_Logging = TRUE;
353ffa53 29
bb3a214a 30 /**
bb3a214a 31 */
00be9182 32 public function __construct() {
4caaa696
EM
33 /**
34 * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
35 * functions and leave the codebase oblivious to the type of CMS
36 * @deprecated
37 * @var bool
38 */
9977c6f5 39 $this->is_drupal = TRUE;
40 $this->supports_form_extensions = TRUE;
41 }
42
4ac7577d
TO
43 /**
44 * @inheritdoc
45 */
46 public function getDefaultFileStorage() {
47 $config = CRM_Core_Config::singleton();
48 $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
49
3403e54b 50 $siteName = $this->parseDrupalSiteNameFromRequest('/files/civicrm');
4ac7577d
TO
51 if ($siteName) {
52 $filesURL = $baseURL . "sites/$siteName/files/civicrm/";
53 }
54 else {
55 $filesURL = $baseURL . "sites/default/files/civicrm/";
56 }
57
be2fb01f 58 return [
4ac7577d
TO
59 'url' => $filesURL,
60 'path' => CRM_Utils_File::baseFilePath(),
be2fb01f 61 ];
4ac7577d
TO
62 }
63
9977c6f5 64 /**
17f443df 65 * @inheritDoc
9977c6f5 66 */
9b873358 67 public function getDefaultSiteSettings($dir) {
9977c6f5 68 $config = CRM_Core_Config::singleton();
69 $siteName = $siteRoot = NULL;
be2fb01f 70 $matches = [];
9977c6f5 71 if (preg_match(
72 '|/sites/([\w\.\-\_]+)/|',
73 $config->templateCompileDir,
74 $matches
75 )) {
76 $siteName = $matches[1];
77 if ($siteName) {
78 $siteName = "/sites/$siteName/";
79 $siteNamePos = strpos($dir, $siteName);
80 if ($siteNamePos !== FALSE) {
81 $siteRoot = substr($dir, 0, $siteNamePos);
82 }
83 }
84 }
85 $url = $config->userFrameworkBaseURL;
be2fb01f 86 return [$url, $siteName, $siteRoot];
9977c6f5 87 }
42e1a97c
E
88
89 /**
fe482240 90 * Check if a resource url is within the drupal directory and format appropriately.
42e1a97c 91 *
3bdca100 92 * @param $url (reference)
42e1a97c 93 *
a6c01b45
CW
94 * @return bool
95 * TRUE for internal paths, FALSE for external. The drupal_add_js fn is able to add js more
16b10e64 96 * efficiently if it is known to be in the drupal site
42e1a97c 97 */
00be9182 98 public function formatResourceUrl(&$url) {
42e1a97c
E
99 $internal = FALSE;
100 $base = CRM_Core_Config::singleton()->resourceBase;
101 global $base_url;
dd85a1e6 102 // Strip query string
103 $q = strpos($url, '?');
104 $url_path = $q ? substr($url, 0, $q) : $url;
42e1a97c 105 // Handle absolute urls
abfa8a7d
EM
106 // compares $url (which is some unknown/untrusted value from a third-party dev) to the CMS's base url (which is independent of civi's url)
107 // to see if the url is within our drupal dir, if it is we are able to treated it as an internal url
dd85a1e6 108 if (strpos($url_path, $base_url) === 0) {
109 $file = trim(str_replace($base_url, '', $url_path), '/');
efe603b4 110 // CRM-18130: Custom CSS URL not working if aliased or rewritten
dd85a1e6 111 if (file_exists(DRUPAL_ROOT . '/' . $file)) {
efe603b4
NG
112 $url = $file;
113 $internal = TRUE;
114 }
42e1a97c 115 }
abfa8a7d 116 // Handle relative urls that are within the CiviCRM module directory
dd85a1e6 117 elseif (strpos($url_path, $base) === 0) {
42e1a97c 118 $internal = TRUE;
dd85a1e6 119 $url = $this->appendCoreDirectoryToResourceBase(dirname(drupal_get_path('module', 'civicrm')) . '/') . trim(substr($url_path, strlen($base)), '/');
42e1a97c
E
120 }
121 return $internal;
122 }
168be77d
E
123
124 /**
125 * In instance where civicrm folder has a drupal folder & a civicrm core folder @ the same level append the
126 * civicrm folder name to the url
127 * See CRM-13737 for discussion of how this allows implementers to alter the folder structure
128 * @todo - this only provides a limited amount of flexiblity - it still expects a 'civicrm' folder with a 'drupal' folder
129 * and is only flexible as to the name of the civicrm folder.
130 *
77855840
TO
131 * @param string $url
132 * Potential resource url based on standard folder assumptions.
a6c01b45
CW
133 * @return string
134 * with civicrm-core directory appended if not standard civi dir
168be77d 135 */
00be9182 136 public function appendCoreDirectoryToResourceBase($url) {
168be77d 137 global $civicrm_root;
2102546d 138 $lastDirectory = basename($civicrm_root);
22e263ad 139 if ($lastDirectory != 'civicrm') {
168be77d
E
140 return $url .= $lastDirectory . '/';
141 }
142 return $url;
143 }
72b140cf
E
144
145 /**
146 * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url)
147 *
17f443df 148 * @inheritDoc
72b140cf 149 */
3bdca100 150 public function url(
17f443df
CW
151 $path = NULL,
152 $query = NULL,
153 $absolute = FALSE,
154 $fragment = NULL,
17f443df 155 $frontend = FALSE,
8de2a34e
SL
156 $forceBackend = FALSE,
157 $htmlize = TRUE
72b140cf
E
158 ) {
159 $config = CRM_Core_Config::singleton();
160 $script = 'index.php';
161
162 $path = CRM_Utils_String::stripPathChars($path);
163
164 if (isset($fragment)) {
165 $fragment = '#' . $fragment;
166 }
167
72b140cf
E
168 $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase;
169
c80e2dbf 170 $separator = '&';
72b140cf
E
171
172 if (!$config->cleanURL) {
173 if (isset($path)) {
174 if (isset($query)) {
175 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
176 }
177 else {
178 return $base . $script . '?q=' . $path . $fragment;
179 }
180 }
181 else {
182 if (isset($query)) {
183 return $base . $script . '?' . $query . $fragment;
184 }
185 else {
186 return $base . $fragment;
187 }
188 }
189 }
190 else {
191 if (isset($path)) {
192 if (isset($query)) {
193 return $base . $path . '?' . $query . $fragment;
194 }
195 else {
196 return $base . $path . $fragment;
197 }
198 }
199 else {
200 if (isset($query)) {
201 return $base . $script . '?' . $query . $fragment;
202 }
203 else {
204 return $base . $fragment;
205 }
206 }
207 }
208 }
32998c82
EM
209
210 /**
17f443df 211 * @inheritDoc
32998c82 212 */
00be9182 213 public function getUserIDFromUserObject($user) {
32998c82
EM
214 return !empty($user->uid) ? $user->uid : NULL;
215 }
2b617cb0
EM
216
217 /**
17f443df
CW
218 * @inheritDoc
219 */
220 public function setMessage($message) {
221 drupal_set_message($message);
222 }
223
224 /**
225 * @inheritDoc
2b617cb0 226 */
00be9182 227 public function getUniqueIdentifierFromUserObject($user) {
2b617cb0
EM
228 return empty($user->mail) ? NULL : $user->mail;
229 }
230
231 /**
17f443df 232 * @inheritDoc
2b617cb0 233 */
00be9182 234 public function getLoggedInUniqueIdentifier() {
2b617cb0
EM
235 global $user;
236 return $this->getUniqueIdentifierFromUserObject($user);
237 }
d0ffa3e4
EM
238
239 /**
17f443df 240 * @inheritDoc
d0ffa3e4 241 */
00be9182 242 public function permissionDenied() {
d0ffa3e4
EM
243 drupal_access_denied();
244 }
59f97da6
EM
245
246 /**
17f443df 247 * @inheritDoc
59f97da6 248 */
00be9182 249 public function getUserRecordUrl($contactID) {
59f97da6 250 $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
353ffa53 251 if (CRM_Core_Session::singleton()
6714d8d2
SL
252 ->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm([
253 'cms:administer users',
254 'cms:view user account',
255 ])
353ffa53 256 ) {
1dc24ed8 257 return $this->url('user/' . $uid);
59f97da6
EM
258 };
259 }
260
261 /**
17f443df 262 * @inheritDoc
59f97da6 263 */
00be9182 264 public function checkPermissionAddUser() {
17f443df 265 return CRM_Core_Permission::check('administer users');
59f97da6 266 }
e0dd98a5 267
e0dd98a5 268 /**
17f443df 269 * @inheritDoc
e0dd98a5 270 */
00be9182 271 public function logger($message) {
b36194a0 272 if (CRM_Core_Config::singleton()->userFrameworkLogging && function_exists('watchdog')) {
be2fb01f 273 watchdog('civicrm', '%message', ['%message' => $message], NULL, WATCHDOG_DEBUG);
e0dd98a5
EM
274 }
275 }
f091327b
CW
276
277 /**
17f443df 278 * @inheritDoc
f091327b 279 */
00be9182 280 public function clearResourceCache() {
f091327b
CW
281 _drupal_flush_css_js();
282 }
f9f361d0 283
7e9cadcf 284 /**
17f443df 285 * @inheritDoc
7e9cadcf 286 */
00be9182 287 public function flush() {
7e9cadcf
EM
288 drupal_flush_all_caches();
289 }
290
291 /**
66e42142 292 * @inheritDoc
7e9cadcf 293 */
00be9182 294 public function getModules() {
be2fb01f 295 $result = [];
7e9cadcf
EM
296 $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1');
297 foreach ($q as $row) {
fe0dbeda 298 $result[] = new CRM_Core_Module('drupal.' . $row->name, $row->status == 1);
7e9cadcf
EM
299 }
300 return $result;
301 }
302
303 /**
304 * Find any users/roles/security-principals with the given permission
305 * and replace it with one or more permissions.
306 *
5a4f6742
CW
307 * @param string $oldPerm
308 * @param array $newPerms
77855840 309 * Array, strings.
7e9cadcf
EM
310 *
311 * @return void
312 */
00be9182 313 public function replacePermission($oldPerm, $newPerms) {
7e9cadcf
EM
314 $roles = user_roles(FALSE, $oldPerm);
315 if (!empty($roles)) {
316 foreach (array_keys($roles) as $rid) {
be2fb01f 317 user_role_revoke_permissions($rid, [$oldPerm]);
7e9cadcf
EM
318 user_role_grant_permissions($rid, $newPerms);
319 }
320 }
321 }
353ffa53 322
7e9cadcf 323 /**
17f443df 324 * @inheritDoc
7e9cadcf 325 */
00be9182 326 public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) {
7e9cadcf
EM
327 if (empty($url)) {
328 return $url;
329 }
330
331 //CRM-7803 -from d7 onward.
332 $config = CRM_Core_Config::singleton();
333 if (function_exists('variable_get') &&
334 module_exists('locale') &&
335 function_exists('language_negotiation_get')
336 ) {
337 global $language;
338
339 //does user configuration allow language
340 //support from the URL (Path prefix or domain)
341 if (language_negotiation_get('language') == 'locale-url') {
342 $urlType = variable_get('locale_language_negotiation_url_part');
343
344 //url prefix
345 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) {
346 if (isset($language->prefix) && $language->prefix) {
347 if ($addLanguagePart) {
348 $url .= $language->prefix . '/';
349 }
350 if ($removeLanguagePart) {
351 $url = str_replace("/{$language->prefix}/", '/', $url);
352 }
353 }
354 }
355 //domain
356 if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN) {
357 if (isset($language->domain) && $language->domain) {
358 if ($addLanguagePart) {
359 $url = (CRM_Utils_System::isSSL() ? 'https' : 'http') . '://' . $language->domain . base_path();
360 }
361 if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) {
362 $url = str_replace('\\', '/', $url);
363 $parseUrl = parse_url($url);
364
365 //kinda hackish but not sure how to do it right
366 //hope http_build_url() will help at some point.
367 if (is_array($parseUrl) && !empty($parseUrl)) {
353ffa53
TO
368 $urlParts = explode('/', $url);
369 $hostKey = array_search($parseUrl['host'], $urlParts);
370 $ufUrlParts = parse_url(CIVICRM_UF_BASEURL);
7e9cadcf 371 $urlParts[$hostKey] = $ufUrlParts['host'];
353ffa53 372 $url = implode('/', $urlParts);
7e9cadcf
EM
373 }
374 }
375 }
376 }
377 }
378 }
379 return $url;
380 }
381
382 /**
17f443df 383 * @inheritDoc
7e9cadcf 384 */
00be9182 385 public function getVersion() {
7e9cadcf
EM
386 return defined('VERSION') ? VERSION : 'Unknown';
387 }
388
8caad0ce 389 /**
390 * @inheritDoc
391 */
392 public function isUserRegistrationPermitted() {
393 if (!variable_get('user_register', TRUE)) {
394 return FALSE;
395 }
396 return TRUE;
397 }
398
63df6889
HD
399 /**
400 * @inheritDoc
401 */
1a6630be 402 public function isPasswordUserGenerated() {
63df6889
HD
403 if (variable_get('user_email_verification', TRUE)) {
404 return FALSE;
405 }
406 return TRUE;
407 }
408
7e9cadcf 409 /**
17f443df 410 * @inheritDoc
7e9cadcf 411 */
00be9182 412 public function updateCategories() {
17f443df 413 // copied this from profile.module. Seems a bit inefficient, but i don't know a better way
7e9cadcf
EM
414 cache_clear_all();
415 menu_rebuild();
416 }
417
7e9cadcf 418 /**
17f443df 419 * @inheritDoc
7e9cadcf 420 */
00be9182 421 public function getUFLocale() {
7e9cadcf
EM
422 // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale
423 // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx
424 // sometimes for CLI based on order called, this might not be set and/or empty
ea9245cc 425 $language = $this->getCurrentLanguage();
7e9cadcf
EM
426
427 if (empty($language)) {
428 return NULL;
429 }
430
ea9245cc 431 if ($language == 'zh-hans') {
7e9cadcf
EM
432 return 'zh_CN';
433 }
434
ea9245cc 435 if ($language == 'zh-hant') {
7e9cadcf
EM
436 return 'zh_TW';
437 }
438
ea9245cc 439 if (preg_match('/^.._..$/', $language)) {
440 return $language;
7e9cadcf
EM
441 }
442
ea9245cc 443 return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
7e9cadcf 444 }
353ffa53 445
fd1f3a26
SV
446 /**
447 * @inheritDoc
448 */
449 public function setUFLocale($civicrm_language) {
450 global $language;
451
452 $langcode = substr($civicrm_language, 0, 2);
453 $languages = language_list();
454
455 if (isset($languages[$langcode])) {
456 $language = $languages[$langcode];
457
458 // Config must be re-initialized to reset the base URL
459 // otherwise links will have the wrong language prefix/domain.
460 $config = CRM_Core_Config::singleton();
461 $config->free();
462
463 return TRUE;
464 }
465
466 return FALSE;
467 }
468
7e9cadcf
EM
469 /**
470 * Perform any post login activities required by the UF -
471 * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
472 * calls hook_user op 'login' and generates a new session.
473 *
3bdca100 474 * @param array $params
7e9cadcf
EM
475 *
476 * FIXME: Document values accepted/required by $params
7e9cadcf 477 */
be2fb01f 478 public function userLoginFinalize($params = []) {
7e9cadcf
EM
479 user_login_finalize($params);
480 }
481
482 /**
17f443df
CW
483 * @inheritDoc
484 */
485 public function getLoginDestination(&$form) {
486 $args = NULL;
487
488 $id = $form->get('id');
489 if ($id) {
490 $args .= "&id=$id";
491 }
492 else {
493 $gid = $form->get('gid');
494 if ($gid) {
495 $args .= "&gid=$gid";
496 }
497 else {
498 // Setup Personal Campaign Page link uses pageId
499 $pageId = $form->get('pageId');
500 if ($pageId) {
501 $component = $form->get('component');
502 $args .= "&pageId=$pageId&component=$component&action=add";
503 }
504 }
505 }
506
507 $destination = NULL;
508 if ($args) {
509 // append destination so user is returned to form they came from after login
510 $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args;
511 }
512 return $destination;
513 }
514
515 /**
516 * Fixme: Why are we overriding the parent function? Seems inconsistent.
517 * This version supplies slightly different params to $this->url (not absolute and html encoded) but why?
ad37ac8e 518 *
519 * @param string $action
520 *
521 * @return string
7e9cadcf 522 */
00be9182 523 public function postURL($action) {
7e9cadcf
EM
524 if (!empty($action)) {
525 return $action;
526 }
527 return $this->url($_GET['q']);
528 }
96025800 529
2b0e7d03
EM
530 /**
531 * Get an array of user details for a contact, containing at minimum the user ID & name.
532 *
533 * @param int $contactID
534 *
535 * @return array
536 * CMS user details including
537 * - id
538 * - name (ie the system user name.
539 */
540 public function getUser($contactID) {
541 $userDetails = parent::getUser($contactID);
542 $user = $this->getUserObject($userDetails['id']);
543 $userDetails['name'] = $user->name;
544 $userDetails['email'] = $user->mail;
545 return $userDetails;
546 }
547
548 /**
549 * Load the user object.
550 *
551 * Note this function still works in drupal 6, 7 & 8 but is deprecated in Drupal 8.
552 *
553 * @param $userID
554 *
555 * @return object
556 */
557 public function getUserObject($userID) {
558 return user_load($userID);
559 }
560
3403e54b
TO
561 /**
562 * Parse the name of the drupal site.
563 *
564 * @param string $civicrm_root
565 *
566 * @return null|string
567 * @deprecated
568 */
569 public function parseDrupalSiteNameFromRoot($civicrm_root) {
570 $siteName = NULL;
571 if (strpos($civicrm_root,
572 DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules'
573 ) === FALSE
574 ) {
575 $startPos = strpos($civicrm_root,
576 DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
577 );
578 $endPos = strpos($civicrm_root,
579 DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
580 );
581 if ($startPos && $endPos) {
582 // if component is in sites/SITENAME/modules
583 $siteName = substr($civicrm_root,
584 $startPos + 7,
585 $endPos - $startPos - 7
586 );
587 }
588 }
589 return $siteName;
590 }
591
bc854509 592 /**
4ac7577d
TO
593 * Determine if Drupal multi-site applies to the current request -- and,
594 * specifically, determine the name of the multisite folder.
bc854509 595 *
4ac7577d
TO
596 * @param string $flagFile
597 * Check if $flagFile exists inside the site dir.
bc854509 598 * @return null|string
4ac7577d
TO
599 * string, e.g. `bar.example.com` if using multisite.
600 * NULL if using the default site.
bc854509 601 */
3403e54b 602 private function parseDrupalSiteNameFromRequest($flagFile = '') {
4ac7577d
TO
603 $phpSelf = array_key_exists('PHP_SELF', $_SERVER) ? $_SERVER['PHP_SELF'] : '';
604 $httpHost = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '';
605 if (empty($httpHost)) {
606 $httpHost = parse_url(CIVICRM_UF_BASEURL, PHP_URL_HOST);
607 if (parse_url(CIVICRM_UF_BASEURL, PHP_URL_PORT)) {
608 $httpHost .= ':' . parse_url(CIVICRM_UF_BASEURL, PHP_URL_PORT);
609 }
610 }
611
612 $confdir = $this->cmsRootPath() . '/sites';
613
614 if (file_exists($confdir . "/sites.php")) {
615 include $confdir . "/sites.php";
616 }
617 else {
be2fb01f 618 $sites = [];
4ac7577d
TO
619 }
620
621 $uri = explode('/', $phpSelf);
622 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($httpHost, '.')))));
623 for ($i = count($uri) - 1; $i > 0; $i--) {
624 for ($j = count($server); $j > 0; $j--) {
625 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
626 if (file_exists("$confdir/$dir" . $flagFile)) {
627 \Civi::$statics[__CLASS__]['drupalSiteName'] = $dir;
628 return \Civi::$statics[__CLASS__]['drupalSiteName'];
629 }
630 // check for alias
631 if (isset($sites[$dir]) && file_exists("$confdir/{$sites[$dir]}" . $flagFile)) {
632 \Civi::$statics[__CLASS__]['drupalSiteName'] = $sites[$dir];
633 return \Civi::$statics[__CLASS__]['drupalSiteName'];
634 }
f6f958e4
TO
635 }
636 }
f6f958e4 637 }
1a6630be 638
ea9245cc 639 /**
640 * Function to return current language of Drupal
641 *
642 * @return string
643 */
644 public function getCurrentLanguage() {
645 global $language;
646 return (!empty($language->language)) ? $language->language : $language;
647 }
648
68e3bc34 649 /**
650 * Is a front end page being accessed.
651 *
652 * Generally this would be a contribution form or other public page as opposed to a backoffice page (like contact edit).
653 *
654 * See https://github.com/civicrm/civicrm-drupal/pull/546/files
655 *
656 * @return bool
657 */
658 public function isFrontEndPage() {
f31f885e 659 $path = CRM_Utils_System::currentPath();
68e3bc34 660
661 // Get the menu for above URL.
662 $item = CRM_Core_Menu::get($path);
e01bf597 663 return !empty($item['is_public']);
68e3bc34 664 }
665
671f655b 666 /**
667 * Start a new session.
668 */
669 public function sessionStart() {
670 if (function_exists('drupal_session_start')) {
671 // https://issues.civicrm.org/jira/browse/CRM-14356
672 if (!(isset($GLOBALS['lazy_session']) && $GLOBALS['lazy_session'] == TRUE)) {
673 drupal_session_start();
674 }
675 $_SESSION = [];
676 }
677 else {
678 session_start();
679 }
680 }
681
08d5b4df
JP
682 /**
683 * Get role names
684 *
685 * @return array|null
686 */
687 public function getRoleNames() {
688 return array_combine(user_roles(), user_roles());
689 }
690
9a8fe710
SL
691 /**
692 * Determine if the Views module exists.
693 *
694 * @return bool
695 */
696 public function viewsExists() {
697 if (function_exists('module_exists') && module_exists('views')) {
698 return TRUE;
699 }
700 return FALSE;
701 }
702
43d84987 703}