src/controllers/ExtensibleSearchPageController.php
public function getForm($request = null, $sorting = true) {

		// Determine whether a search engine has been selected.

		$engine = $this->data()->SearchEngine;
		$configuration = Config::inst();
		$classes = $configuration->get(FulltextSearchable::class, 'searchable_classes');
		if(!$engine || (($engine !== 'Full-Text') && !ClassInfo::exists($engine)) || (($engine === 'Full-Text') && (!is_array($classes) || (count($classes) === 0)))) {

			// The search engine has not been selected.

			return null;
		}

		// Determine whether the request has been passed through.

		if(is_null($request)) {
			$request = $this->getRequest();
		}

		// Display the search.

		$fields = FieldList::create(
			TextField::create(
				'Search',
				_t('EXTENSIBLE_SEARCH.SEARCH', 'Search'),
				$request->getVar('Search')
			)->addExtraClass('extensible-search')->setAttribute('data-suggestions-enabled', $configuration->get(ExtensibleSearchSuggestion::class, 'enable_suggestions') ? 'true' : 'false')->setAttribute('data-extensible-search-page', $this->data()->ID)
		);

		// Determine whether sorting has been passed through from the template.

		if(is_string($sorting)) {
			$sorting = ($sorting === 'true');
		}

		// Determine whether to display the sorting selection.

		if($sorting) {

			// Display the sorting selection.

			$fields->push(DropdownField::create(
				'SortBy',
				_t('EXTENSIBLE_SEARCH.SORT_BY', 'Sort By'),
				$this->data()->getSelectableFields(),
				$request->getVar('SortBy') ? $request->getVar('SortBy') : $this->data()->SortBy
			)->setHasEmptyDefault(true));
			$fields->push(DropdownField::create(
				'SortDirection',
				_t('EXTENSIBLE_SEARCH.SORT_DIRECTION', 'Sort Direction'),
				array(
					'DESC' => _t('EXTENSIBLE_SEARCH.DESCENDING', 'Descending'),
					'ASC' => _t('EXTENSIBLE_SEARCH.ASCENDING', 'Ascending')
				),
				$request->getVar('SortDirection') ? $request->getVar('SortDirection') : $this->data()->SortDirection
			)->setHasEmptyDefault(true));
		}

		// Instantiate the search form.

		$form = SearchForm::create(
			$this,
			'getForm',
			$fields,
			FieldList::create(
				FormAction::create(
					'getSearchResults',
					_t('EXTENSIBLE_SEARCH.GO', 'Go')
				)
			)
		);

		// When using the full-text search engine, the classes to search needs to be initialised.

		if($engine === 'Full-Text') {
			$form->classesToSearch($classes);
		}

		// Allow extension customisation.

		$this->extend('updateExtensibleSearchForm', $form);
		return $form;
	}
public function getForm($request = null, $sorting = true) {

		// Determine whether a search engine has been selected.

		$engine = $this->data()->SearchEngine;
		$configuration = Config::inst();
		$classes = $configuration->get(FulltextSearchable::class, 'searchable_classes');
		if(!$engine || (($engine !== 'Full-Text') && !ClassInfo::exists($engine)) || (($engine === 'Full-Text') && (!is_array($classes) || (count($classes) === 0)))) {

			// The search engine has not been selected.

			return null;
		}

		// Determine whether the request has been passed through.

		if(is_null($request)) {
			$request = $this->getRequest();
		}

		// Display the search.

		$fields = FieldList::create(
			TextField::create(
				'Search',
				_t('EXTENSIBLE_SEARCH.SEARCH', 'Search'),
				$request->getVar('Search')
			)->addExtraClass('extensible-search')->setAttribute('data-suggestions-enabled', $configuration->get(ExtensibleSearchSuggestion::class, 'enable_suggestions') ? 'true' : 'false')->setAttribute('data-extensible-search-page', $this->data()->ID)
		);

		// Determine whether sorting has been passed through from the template.

		if(is_string($sorting)) {
			$sorting = ($sorting === 'true');
		}

		// Determine whether to display the sorting selection.

		if($sorting) {

			// Display the sorting selection.

			$fields->push(DropdownField::create(
				'SortBy',
				_t('EXTENSIBLE_SEARCH.SORT_BY', 'Sort By'),
				$this->data()->getSelectableFields(),
				$request->getVar('SortBy') ? $request->getVar('SortBy') : $this->data()->SortBy
			)->setHasEmptyDefault(true));
			$fields->push(DropdownField::create(
				'SortDirection',
				_t('EXTENSIBLE_SEARCH.SORT_DIRECTION', 'Sort Direction'),
				array(
					'DESC' => _t('EXTENSIBLE_SEARCH.DESCENDING', 'Descending'),
					'ASC' => _t('EXTENSIBLE_SEARCH.ASCENDING', 'Ascending')
				),
				$request->getVar('SortDirection') ? $request->getVar('SortDirection') : $this->data()->SortDirection
			)->setHasEmptyDefault(true));
		}

		// Instantiate the search form.

		$form = SearchForm::create(
			$this,
			'getForm',
			$fields,
			FieldList::create(
				FormAction::create(
					'getSearchResults',
					_t('EXTENSIBLE_SEARCH.GO', 'Go')
				)
			)
		);

		// When using the full-text search engine, the classes to search needs to be initialised.

		if($engine === 'Full-Text') {
			$form->classesToSearch($classes);
		}

		// Allow extension customisation.

		$this->extend('updateExtensibleSearchForm', $form);
		return $form;
	}
public function getForm ( $ request = null , $ sorting = true ) { // Determine whether a search engine has been selected. $ engine = $ this -> data ( ) -> SearchEngine ; $ configuration = Config :: inst ( ) ; $ classes = $ configuration -> get ( FulltextSearchable :: class , 'searchable_classes' ) ; if ( ! $ engine || ( ( $ engine !== 'Full-Text' ) && ! ClassInfo :: exists ( $ engine ) ) || ( ( $ engine === 'Full-Text' ) && ( ! is_array ( $ classes ) || ( count ( $ classes ) === 0 ) ) ) ) { // The search engine has not been selected. return null ; } // Determine whether the request has been passed through. if ( is_null ( $ request ) ) { $ request = $ this -> getRequest ( ) ; } // Display the search. $ fields = FieldList :: create ( TextField :: create ( 'Search' , _t ( 'EXTENSIBLE_SEARCH.SEARCH' , 'Search' ) , $ request -> getVar ( 'Search' ) ) -> addExtraClass ( 'extensible-search' ) -> setAttribute ( 'data-suggestions-enabled' , $ configuration -> get ( ExtensibleSearchSuggestion :: class , 'enable_suggestions' ) ? 'true' : 'false' ) -> setAttribute ( 'data-extensible-search-page' , $ this -> data ( ) -> ID ) ) ; // Determine whether sorting has been passed through from the template. if ( is_string ( $ sorting ) ) { $ sorting = ( $ sorting === 'true' ) ; } // Determine whether to display the sorting selection. if ( $ sorting ) { // Display the sorting selection. $ fields -> push ( DropdownField :: create ( 'SortBy' , _t ( 'EXTENSIBLE_SEARCH.SORT_BY' , 'Sort By' ) , $ this -> data ( ) -> getSelectableFields ( ) , $ request -> getVar ( 'SortBy' ) ? $ request -> getVar ( 'SortBy' ) : $ this -> data ( ) -> SortBy ) -> setHasEmptyDefault ( true ) ) ; $ fields -> push ( DropdownField :: create ( 'SortDirection' , _t ( 'EXTENSIBLE_SEARCH.SORT_DIRECTION' , 'Sort Direction' ) , array ( 'DESC' => _t ( 'EXTENSIBLE_SEARCH.DESCENDING' , 'Descending' ) , 'ASC' => _t ( 'EXTENSIBLE_SEARCH.ASCENDING' , 'Ascending' ) ) , $ request -> getVar ( 'SortDirection' ) ? $ request -> getVar ( 'SortDirection' ) : $ this -> data ( ) -> SortDirection ) -> setHasEmptyDefault ( true ) ) ; } // Instantiate the search form. $ form = SearchForm :: create ( $ this , 'getForm' , $ fields , FieldList :: create ( FormAction :: create ( 'getSearchResults' , _t ( 'EXTENSIBLE_SEARCH.GO' , 'Go' ) ) ) ) ; // When using the full-text search engine, the classes to search needs to be initialised. if ( $ engine === 'Full-Text' ) { $ form -> classesToSearch ( $ classes ) ; } // Allow extension customisation. $ this -> extend ( 'updateExtensibleSearchForm' , $ form ) ; return $ form ; }
Instantiate the search form.

@parameter <{REQUEST}> http request
@parameter <{DISPLAY_SORTING}> boolean
@return search form
Instantiate the search form .