Merge pull request #10394 from JMAConsulting/DonotExport
[civicrm-core.git] / Civi / Angular / Page / Main.php
CommitLineData
e7ff7042 1<?php
39c3d5e9 2namespace Civi\Angular\Page;
e7ff7042
TO
3
4/**
5 * This page is simply a container; any Angular modules defined by CiviCRM (or by CiviCRM extensions)
6 * will be activated on this page.
7 *
8 * @link https://issues.civicrm.org/jira/browse/CRM-14479
9 */
39c3d5e9 10class Main extends \CRM_Core_Page {
b20ea913 11
e7ff7042 12 /**
fe482240 13 * The weight to assign to any Angular JS module files.
e7ff7042
TO
14 */
15 const DEFAULT_MODULE_WEIGHT = 200;
16
2f6c50d5 17 /**
4d93c42f
TO
18 * The resource manager.
19 *
20 * Do not use publicly. Inject your own copy!
21 *
39c3d5e9 22 * @var \CRM_Core_Resources
b20ea913 23 * @deprecated
2f6c50d5 24 */
4d93c42f 25 public $res;
2f6c50d5 26
16072ce1 27 /**
4d93c42f
TO
28 * The Angular module manager.
29 *
30 * Do not use publicly. Inject your own copy!
31 *
39c3d5e9 32 * @var \Civi\Angular\Manager
b20ea913 33 * @deprecated
16072ce1 34 */
4d93c42f 35 public $angular;
16072ce1 36
2c60bace
FG
37 /**
38 * The region of the page into which JavaScript will be loaded.
39 *
40 * @var String
b20ea913 41 * @deprecated
2c60bace
FG
42 */
43 public $region;
44
2f6c50d5
TO
45 /**
46 * @param string $title
47 * Title of the page.
48 * @param int $mode
49 * Mode of the page.
39c3d5e9 50 * @param \CRM_Core_Resources|null $res
2f6c50d5
TO
51 * Resource manager.
52 */
53 public function __construct($title = NULL, $mode = NULL, $res = NULL) {
54 parent::__construct($title, $mode);
39c3d5e9 55 $this->res = \CRM_Core_Resources::singleton();
048222df 56 $this->angular = \Civi::service('angular');
6aeeacaf 57 $this->region = \CRM_Utils_Request::retrieve('snippet', 'String') ? 'ajax-snippet' : 'html-header';
2f6c50d5
TO
58 }
59
b5c2afd0
EM
60 /**
61 * This function takes care of all the things common to all
62 * pages. This typically involves assigning the appropriate
63 * smarty variable :)
64 *
a6c01b45
CW
65 * @return string
66 * The content generated by running this page
b5c2afd0 67 */
00be9182 68 public function run() {
6aeeacaf 69 $this->registerResources();
4b07d5bd
TO
70 return parent::run();
71 }
72
a0ee3941 73 /**
2f6c50d5 74 * Register resources required by Angular.
a0ee3941 75 */
6aeeacaf 76 public function registerResources() {
b20ea913
TO
77 $loader = new \Civi\Angular\AngularLoader();
78 $loader->setPageName('civicrm/a');
79 $loader->setModules(array('crmApp'));
80 $loader->load();
81916bee 81
337fc3e6 82 // If trying to load an Angular page via AJAX, the route must be passed as a
2c60bace
FG
83 // URL parameter, since the server doesn't receive information about
84 // URL fragments (i.e, what comes after the #).
337fc3e6 85 \CRM_Core_Resources::singleton()->addSetting(array(
b20ea913
TO
86 'crmApp' => array(
87 'defaultRoute' => NULL,
88 ),
337fc3e6
FG
89 'angularRoute' => \CRM_Utils_Request::retrieve('route', 'String'),
90 ));
2f6c50d5 91 }
e807a9a6 92
fe158128 93 /**
b20ea913 94 * @inheritdoc
fe158128 95 */
b20ea913
TO
96 public function getTemplateFileName() {
97 return 'Civi/Angular/Page/Main.tpl';
fe158128
TO
98 }
99
b5c2afd0 100}