mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
Move advanced form out to it's own class
Make page title customizable through the Config system (Fixes #44)
This commit is contained in:
parent
2c00a3b20f
commit
e80edc445e
@ -31,6 +31,11 @@ class DocumentationViewer extends Controller {
|
|||||||
*/
|
*/
|
||||||
private static $google_analytics_code = '';
|
private static $google_analytics_code = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $documentation_title = 'SilverStripe Documentation';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -686,7 +691,7 @@ class DocumentationViewer extends Controller {
|
|||||||
$output = "";
|
$output = "";
|
||||||
|
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
$output = $page->Title .' - '. $output;
|
$output = $page->Title .' – '. $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
@ -922,55 +927,17 @@ class DocumentationViewer extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function AdvancedSearchForm() {
|
public function AdvancedSearchForm() {
|
||||||
$entities = DocumentationService::get_registered_entities();
|
$entities = DocumentationService::get_registered_entities();
|
||||||
$versions = array();
|
|
||||||
|
|
||||||
foreach($entities as $entity) {
|
return new DocumentationAdvancedSearchForm($this);
|
||||||
$versions[$entity->getFolder()] = $entity->getVersions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// get a list of all the unique versions
|
|
||||||
$uniqueVersions = array_unique(ArrayLib::flatten(array_values($versions)));
|
|
||||||
asort($uniqueVersions);
|
|
||||||
$uniqueVersions = array_combine($uniqueVersions,$uniqueVersions);
|
|
||||||
|
|
||||||
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
|
|
||||||
|
|
||||||
// klude to take an array of objects down to a simple map
|
|
||||||
$entities = new ArrayList($entities);
|
|
||||||
$entities = $entities->map('Folder', 'Title');
|
|
||||||
|
|
||||||
// if we haven't gone any search limit then we're searching everything
|
|
||||||
$searchedEntities = $this->getSearchedEntities();
|
|
||||||
if(count($searchedEntities) < 1) $searchedEntities = $entities;
|
|
||||||
|
|
||||||
$searchedVersions = $this->getSearchedVersions();
|
|
||||||
if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions;
|
|
||||||
|
|
||||||
$fields = new FieldList(
|
|
||||||
new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q),
|
|
||||||
new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities),
|
|
||||||
new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'),
|
|
||||||
$uniqueVersions, $searchedVersions
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$actions = new FieldList(
|
|
||||||
new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search'))
|
|
||||||
);
|
|
||||||
$required = new RequiredFields(array('Search'));
|
|
||||||
|
|
||||||
$form = new Form($this, 'AdvancedSearchForm', $fields, $actions, $required);
|
|
||||||
$form->disableSecurityToken();
|
|
||||||
$form->setFormMethod('GET');
|
|
||||||
$form->setFormAction(self::$link_base . 'DocumentationSearchForm');
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the Advanced SearchForm can be displayed
|
* Check if the Advanced SearchForm can be displayed. It is enabled by
|
||||||
* enabled by default, to disable use:
|
* default, to disable use:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
* DocumentationSearch::enable_advanced_search(false);
|
* DocumentationSearch::enable_advanced_search(false);
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -1094,4 +1061,11 @@ class DocumentationViewer extends Controller {
|
|||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDocumentationTitle() {
|
||||||
|
return Config::inst()->get('DocumentationViewer', 'documentation_title');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
66
code/forms/DocumentationAdvancedSearchForm.php
Normal file
66
code/forms/DocumentationAdvancedSearchForm.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package docsviewer
|
||||||
|
*/
|
||||||
|
class DocumentationAdvancedSearchForm extends Form {
|
||||||
|
|
||||||
|
public function __construct($controller) {
|
||||||
|
$entities = DocumentationService::get_registered_entities();
|
||||||
|
$versions = array();
|
||||||
|
|
||||||
|
foreach($entities as $entity) {
|
||||||
|
$versions[$entity->getFolder()] = $entity->getVersions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get a list of all the unique versions
|
||||||
|
$uniqueVersions = array_unique(ArrayLib::flatten(array_values($versions)));
|
||||||
|
asort($uniqueVersions);
|
||||||
|
$uniqueVersions = array_combine($uniqueVersions,$uniqueVersions);
|
||||||
|
|
||||||
|
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
|
||||||
|
|
||||||
|
// klude to take an array of objects down to a simple map
|
||||||
|
$entities = new ArrayList($entities);
|
||||||
|
$entities = $entities->map('Folder', 'Title');
|
||||||
|
|
||||||
|
// if we haven't gone any search limit then we're searching everything
|
||||||
|
$searchedEntities = $controller->getSearchedEntities();
|
||||||
|
|
||||||
|
if(count($searchedEntities) < 1) {
|
||||||
|
$searchedEntities = $entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
$searchedVersions = $controller->getSearchedVersions();
|
||||||
|
|
||||||
|
if(count($searchedVersions) < 1) {
|
||||||
|
$searchedVersions = $uniqueVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = new FieldList(
|
||||||
|
new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q),
|
||||||
|
new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities),
|
||||||
|
new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'),
|
||||||
|
$uniqueVersions, $searchedVersions
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$actions = new FieldList(
|
||||||
|
new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$required = new RequiredFields(array('Search'));
|
||||||
|
|
||||||
|
parent::__construct(
|
||||||
|
$controller,
|
||||||
|
'AdvancedSearchForm',
|
||||||
|
$fields,
|
||||||
|
$actions,
|
||||||
|
$required
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->disableSecurityToken();
|
||||||
|
$this->setFormMethod('GET');
|
||||||
|
$this->setFormAction(self::$link_base . 'DocumentationSearchForm');
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specific documentation page within a {@link DocumentationEntity}. Maps to
|
* A specific documentation page within a {@link DocumentationEntity}.
|
||||||
* a file on the file system. Note that the URL to access this documentation
|
*
|
||||||
* page may not always be the file name. If the file contains meta data with
|
* Maps to a file on the file system. Note that the URL to access this page may
|
||||||
* a nicer URL then it will use that.
|
* not always be the file name. If the file contains meta data with a nicer URL
|
||||||
|
* sthen it will use that.
|
||||||
*
|
*
|
||||||
* @package docsviewer
|
* @package docsviewer
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<% base_tag %>
|
<% base_tag %>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title><% if PageTitle %>$PageTitle –<% end_if %>SilverStripe Documentation</title>
|
<title><% if PageTitle %>$PageTitle<% end_if %>$DocumentationTitle</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
Loading…
Reference in New Issue
Block a user