mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Search didn't respect searchableClasses passed to FulltextSearchable::enable() (from r111464)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112905 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0d19b45155
commit
dd1c02cd90
@ -27,7 +27,9 @@ class ContentControllerSearchExtension extends Extension {
|
|||||||
$actions = new FieldSet(
|
$actions = new FieldSet(
|
||||||
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
||||||
);
|
);
|
||||||
return new SearchForm($this->owner, 'SearchForm', $fields, $actions);
|
$form = new SearchForm($this->owner, 'SearchForm', $fields, $actions);
|
||||||
|
$form->classesToSearch(FulltextSearchable::$searchableClasses);
|
||||||
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class FulltextSearchable extends DataObjectDecorator {
|
class FulltextSearchable extends DataObjectDecorator {
|
||||||
protected $searchFields;
|
protected $searchFields;
|
||||||
|
static $searchableClasses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable the default configuration of MySQL full-text searching on the given data classes.
|
* Enable the default configuration of MySQL full-text searching on the given data classes.
|
||||||
@ -25,6 +26,7 @@ class FulltextSearchable extends DataObjectDecorator {
|
|||||||
throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'");
|
throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self::$searchableClasses = $searchableClasses;
|
||||||
|
|
||||||
Object::add_extension("ContentController", "ContentControllerSearchExtension");
|
Object::add_extension("ContentController", "ContentControllerSearchExtension");
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,15 @@ class SearchForm extends Form {
|
|||||||
$this->classesToSearch = $legalClasses;
|
$this->classesToSearch = $legalClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the classes to search
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getClassesToSearch() {
|
||||||
|
return $this->classesToSearch;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return dataObjectSet of the results using $_REQUEST to get info from form.
|
* Return dataObjectSet of the results using $_REQUEST to get info from form.
|
||||||
* Wraps around {@link searchEngine()}.
|
* Wraps around {@link searchEngine()}.
|
||||||
|
13
tests/search/ContentControllerSearchExtensionTest.php
Normal file
13
tests/search/ContentControllerSearchExtensionTest.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
class ContentControllerSearchExtensionTest extends SapphireTest {
|
||||||
|
|
||||||
|
function testCustomSearchFormClassesToTest() {
|
||||||
|
FulltextSearchable::enable('File');
|
||||||
|
|
||||||
|
$page = new Page();
|
||||||
|
$controller = new ContentController($page);
|
||||||
|
$form = $controller->SearchForm();
|
||||||
|
|
||||||
|
$this->assertEquals(array('File'), $form->getClassesToSearch());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user