function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->removeByName("Title");
        $fields->addFieldToTab("Root.Main", new HeaderField($name = "TitleHeader", "search for: '" . $this->Title . "'", 1), "RedirectTo");
        $fields->removeByName("Recommendations");
        if (!$this->RedirectTo) {
            $source = SiteTree::get()->filter(array("ShowInSearch" => 1))->exclude(array("ClassName" => "SearchPlusPage"));
            $sourceArray = $sourc->map()->toArray();
            //$fields->addFieldToTab("Root.Main", new MultiSelectField($name = "Recommendations", $title = "Recommendations", $sourceArray));
            $fields->addFieldToTab("Root.Main", new TreeMultiselectField($name = "Recommendations", $title = "Recommendations", "SiteTree"));
        } else {
            $fields->addFieldToTab("Root.Main", new LiteralField($name = "Recommendations", '<p>This search phrase cannot have recommendations, because it redirects to <i>' . $this->RedirectTo . '</i></p>'));
        }
        $page = SearchPlusPage::get()->first();
        if (!$page) {
            user_error("Make sure to create a SearchPlusPage to make proper use of this module", E_USER_NOTICE);
        } else {
            $fields->addFieldToTab("Root.Main", new LiteralField($name = "BackLinks", $content = '<p>
						Review a graph of all <a href="' . $page->Link() . 'popularsearchwords/100/10/">Popular Search Phrases</a> OR
						<a href="' . $page->Link() . 'results/?Search=' . urlencode($this->Title) . '&amp;action_results=Search&amp;redirect=1">try this search</a>.
					</p>'));
        }
        return $fields;
    }
 function SearchPlusForm($name = "SearchForm", $fieldName = "Search", $fieldLabel = '')
 {
     $action = $this->getRequest()->param("Action");
     $page = SearchPlusPage::get()->first();
     if ($page) {
         //!in_array($action, array("login", "logout")) &&
         if (!$fieldLabel) {
             if (isset($_REQUEST[$fieldName])) {
                 $searchText = $_REQUEST[$fieldName];
                 //we set $_REQUEST["Search"] below because it is also used by things like Text::ContextSummary
                 $_REQUEST["Search"] = $_REQUEST[$fieldName];
             } elseif (isset($_REQUEST["Search"])) {
                 $searchText = $_REQUEST["Search"];
             } else {
                 $searchText = 'Search';
             }
         } else {
             $searchText = '';
         }
         $field = new TextField($fieldName, $fieldLabel, $searchText);
         $fields = new FieldList($field);
         $actions = new FieldList(new FormAction('results', 'Search'));
         $form = new SearchForm($this, $name, $fields, $actions);
         $form->setFormAction($page->Link() . "results/");
         $form->setPageLength(Config::inst()->get("SearchPlusPage", "result_length"));
         $form->unsetValidator();
         return $form;
     } elseif (!$page) {
         user_error("You need to create a SearchPlusPage to have a search box", E_USER_NOTICE);
     }
 }
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->ParentID) {
         if ($page = SearchPlusPage::get()->first()) {
             $this->ParentID = $page->ID;
         } else {
             user_error("Make sure to create a SearchPlusPage", E_USER_NOTICE);
         }
     }
 }
 public function canCreate($member = null)
 {
     return SearchPlusPage::get()->count ? false : true;
 }