Ejemplo n.º 1
0
 public function testCmsClassDetection()
 {
     // Get CMS classes and check that:
     //	1.) SecurityAdmin is included
     //	2.) LeftAndMain & ModelAdmin are excluded
     $cmsClasses = CMSMenu::get_cms_classes();
     $this->assertContains('SecurityAdmin', $cmsClasses, 'SecurityAdmin included in valid CMS Classes');
     $this->assertNotContains('LeftAndMain', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
     $this->assertNotContains('ModelAdmin', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
 }
 /**
  * Gets a list of url_pattern => controller k/v pairs for each LeftAndMain derived controller
  */
 public static function rules()
 {
     if (self::$_rules === null) {
         self::$_rules = array();
         // Map over the array calling add_rule_for_controller on each
         $classes = CMSMenu::get_cms_classes(null, true, CMSMenu::URL_PRIORITY);
         array_map(array(__CLASS__, 'add_rule_for_controller'), $classes);
     }
     return self::$_rules;
 }
 /**
  * Gets a list of url_pattern => controller k/v pairs for each LeftAndMain derived controller
  */
 public static function rules()
 {
     if (self::$_rules === null) {
         self::$_rules = array();
         // Build an array of class => url_priority k/v pairs
         $classes = array();
         foreach (CMSMenu::get_cms_classes() as $class) {
             $classes[$class] = Config::inst()->get($class, 'url_priority', Config::FIRST_SET);
         }
         // Sort them so highest priority item is first
         arsort($classes, SORT_NUMERIC);
         // Map over the array calling add_rule_for_controller on each
         array_map(array(__CLASS__, 'add_rule_for_controller'), array_keys($classes));
     }
     return self::$_rules;
 }
 /**
  * returns a list of all model admin links
  * @return Array(String)
  */
 private function ListOfAllModelAdmins()
 {
     $models = array();
     $modelAdmins = CMSMenu::get_cms_classes("ModelAdmin");
     if ($modelAdmins && count($modelAdmins)) {
         foreach ($modelAdmins as $modelAdmin) {
             if ($modelAdmin != "ModelAdminEcommerceBaseClass") {
                 $obj = singleton($modelAdmin);
                 $modelAdminLink = $obj->Link();
                 $models[] = $modelAdminLink;
                 $modelsToAdd = $obj->getManagedModels();
                 if ($modelsToAdd && count($modelsToAdd)) {
                     foreach ($modelsToAdd as $key => $model) {
                         if (is_array($model) || !is_subclass_of($model, "DataObject")) {
                             $model = $key;
                         }
                         if (!is_subclass_of($model, "DataObject")) {
                             continue;
                         }
                         $modelLink = $modelAdminLink . $model . "/";
                         $models[] = $modelLink;
                         $models[] = $modelLink . "EditForm/field/" . $model . "/item/new/";
                         if ($item = $model::get()->First()) {
                             $models[] = $modelLink . "EditForm/field/" . $model . "/item/" . $item->ID . "/edit";
                         }
                     }
                 }
             }
         }
     }
     return $models;
 }
 /**
  * Gets the combined configuration of all LeafAndMain subclasses required by the client app.
  *
  * @return array
  *
  * WARNING: Experimental API
  */
 public function getCombinedClientConfig()
 {
     $combinedClientConfig = ['sections' => []];
     $cmsClassNames = CMSMenu::get_cms_classes('LeftAndMain', true, CMSMenu::URL_PRIORITY);
     foreach ($cmsClassNames as $className) {
         $combinedClientConfig['sections'][$className] = Injector::inst()->get($className)->getClientConfig();
     }
     // Pass in base url (absolute and relative)
     $combinedClientConfig['baseUrl'] = Director::baseURL();
     $combinedClientConfig['absoluteBaseUrl'] = Director::absoluteBaseURL();
     $combinedClientConfig['adminUrl'] = AdminRootController::admin_url();
     // Get "global" CSRF token for use in JavaScript
     $token = SecurityToken::inst();
     $combinedClientConfig[$token->getName()] = $token->getValue();
     // Set env
     $combinedClientConfig['environment'] = Director::get_environment_type();
     $combinedClientConfig['debugging'] = $this->config()->client_debugging;
     return Convert::raw2json($combinedClientConfig);
 }