class PartyAlterStatusFilter in Party 7
Same name and namespace in other branches
- 8.2 includes/search_api/callback_status_filter.inc \PartyAlterStatusFilter
Search API data alteration callback that filters out hidden parties.
Hierarchy
- class \SearchApiAbstractAlterCallback implements SearchApiAlterCallbackInterface
- class \PartyAlterStatusFilter
Expanded class hierarchy of PartyAlterStatusFilter
1 string reference to 'PartyAlterStatusFilter'
- party_search_api_alter_callback_info in ./
party.module - Implements hook_search_api_alter_callback_info().
File
- includes/
search_api/ callback_status_filter.inc, line 9 - Status filter for search api.
View source
class PartyAlterStatusFilter extends SearchApiAbstractAlterCallback {
/**
* {@inheritdoc}
*/
public function supportsIndex(SearchApiIndex $index) {
return $index->item_type == 'party';
}
/**
* {@inheritdoc}
*/
public function configurationForm() {
$form = array();
$form['archived'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude archived parties'),
'#default_value' => isset($this->options['archived']) ? $this->options['archived'] : NULL,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function alterItems(array &$items) {
foreach ($items as $id => $item) {
if (!$this
->checkParty($item)) {
unset($items[$id]);
}
}
}
/**
* Run the appropriate checks on a party depending on the configuration.
*
* @param \Party $party
* The party we are checking.
*
* @return bool
* TRUE if this party passes the filter, FALSE if it doesn't.
*/
protected function checkParty(Party $party) {
// Hidden always gets filtered out.
if ($party->hidden) {
return FALSE;
}
// If we've chosen to filter out archived, check it.
if (!empty($this->options['archived']) && $party->archived) {
return FALSE;
}
// If we've got this far, we've passed the filter.
return TRUE;
}
}