*/
protected $queryCallable;
+ /**
+ * Value that defined when this filter is considered active
+ *
+ * @var bool $activeValue
+ */
+ protected $activeValue;
+
/**
* Create a new filter with the specified configuration.
*
* to true. It does not need to be set if the exact same filter is simply visible
* on both.
* * $filterDefinition['default'] bool Default
+ * * $filterDefinition['activeValue'] bool This filter is considered active when
+ * its value is equal to its activeValue. Default is true.
* * $filterDefinition['priority'] int Priority integer. Higher value means higher
* up in the group's filter list.
* * $filterDefinition['queryCallable'] callable Callable accepting parameters, used
}
if ( isset( $filterDefinition['default'] ) ) {
- $this->defaultValue = $filterDefinition['default'];
+ $this->setDefault( $filterDefinition['default'] );
} else {
throw new MWException( 'You must set a default' );
}
if ( isset( $filterDefinition['queryCallable'] ) ) {
$this->queryCallable = $filterDefinition['queryCallable'];
}
+
+ if ( isset( $filterDefinition['activeValue'] ) ) {
+ $this->activeValue = $filterDefinition['activeValue'];
+ } else {
+ $this->activeValue = true;
+ }
}
/**
*/
public function getDefault( $structuredUI = false ) {
return $this->isReplacedInStructuredUi && $structuredUI ?
- false :
+ !$this->activeValue :
$this->defaultValue;
}
/**
- * Sets default
+ * Sets default. It must be a boolean.
+ *
+ * It will be coerced to boolean.
*
* @param bool $defaultValue
*/
public function setDefault( $defaultValue ) {
- $this->defaultValue = $defaultValue;
+ $this->defaultValue = (bool)$defaultValue;
}
/**
*/
public function isSelected( FormOptions $opts ) {
return !$opts[ $this->getName() ] &&
- array_filter( $this->getSiblings(), function ( $sibling ) use ( $opts ) {
- return $opts[ $sibling->getName() ];
- } );
+ array_filter(
+ $this->getSiblings(),
+ function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
+ return $opts[ $sibling->getName() ];
+ }
+ );
+ }
+
+ /**
+ * @param FormOptions $opts Query parameters merged with defaults
+ * @param bool $isStructuredUI Whether the structured UI is currently enabled
+ * @return bool Whether this filter should be considered active
+ */
+ public function isActive( FormOptions $opts, $isStructuredUI ) {
+ if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
+ return false;
+ }
+
+ return $opts[ $this->getName() ] === $this->activeValue;
}
}