SilverStripe Search

SiteState Uses Configurable, Injectable

AbstractYes

Class SiteState

Determine and apply the state of the site currently. This is used at index-time to figure out what state to index. An example of this is the FluentSearchVariant extension from Fluent.

Fluent uses the old SearchVariant method, which is actually not that bad a concept. These "Variants", now called "States" set the state of the site to a required setting for each available state.

States SHOULD add their own states through an extension of this class and implement , otherwise it won't be called.

States, options, etc. are simplified for a more streamlined approach

Table of Contents

Constants

DEFAULT_STATE  = 'default'

Properties

$enabled  : bool
$states  : array<string|int, mixed>
States that can be applied
$variants  : array<string|int, mixed>
Variants of SiteState that can be activated
$defaultStates  : array<string|int, mixed>
$state  : string

Methods

addState()  : void
Add a state
addStates()  : void
Add multiple states
alterQuery()  : void
Alter the query for each instance
appliesToEnvironment()  : bool
Does this state apply to the current object/environment settings
currentStates()  : array<string|int, mixed>
Get the current state of every variant
getDefaultStates()  : array<string|int, mixed>
Get the states set as default
getStates()  : array<string|int, mixed>
Get available states
hasExtension()  : bool
Does this class, it's parent (or optionally one of it's children) have the passed extension attached?
isApplicable()  : bool
Is this extension applied and instantiable, and should it be applied to the current state of the site
isEnabled()  : bool
Is this state enabled
setDefaultStates()  : void
Set the default states
setEnabled()  : void
Set the state to whatever is required. Most commonly true
setStates()  : void
Set states
variants()  : array<string|int, mixed>
Returns an array of variants.
withState()  : void
Activate a site state for indexing

Constants

DEFAULT_STATE

public mixed DEFAULT_STATE = 'default'

Properties

$enabled

public bool $enabled = true

Is this State enabled

$states

States that can be applied

public static array<string|int, mixed> $states = [self::DEFAULT_STATE]

$variants

Variants of SiteState that can be activated

public static array<string|int, mixed> $variants = []

$defaultStates

protected static array<string|int, mixed> $defaultStates = []

Default states

$state

protected string $state

current state

Methods

addState()

Add a state

public static addState( $state) : void
Parameters
$state :
Tags
static

addStates()

Add multiple states

public static addStates(array<string|int, mixed> $states) : void
Parameters
$states : array<string|int, mixed>
Tags
static

alterQuery()

Alter the query for each instance

public static alterQuery(BaseQuery &$query) : void
Parameters
$query : BaseQuery
Tags
throws
ReflectionException

appliesToEnvironment()

Does this state apply to the current object/environment settings

public appliesToEnvironment() : bool
Return values
bool

currentStates()

Get the current state of every variant

public static currentStates() : array<string|int, mixed>
Tags
static
throws
ReflectionException
Return values
array<string|int, mixed>

getDefaultStates()

Get the states set as default

public static getDefaultStates() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStates()

Get available states

public static getStates() : array<string|int, mixed>
Tags
static
Return values
array<string|int, mixed>

hasExtension()

Does this class, it's parent (or optionally one of it's children) have the passed extension attached?

public static hasExtension(string $class, string $extension) : bool
Parameters
$class : string
$extension : string
Tags
static
throws
ReflectionException
Return values
bool

isApplicable()

Is this extension applied and instantiable, and should it be applied to the current state of the site

public static isApplicable( $variantClass) : bool
Parameters
$variantClass :
Tags
static
throws
ReflectionException
Return values
bool

isEnabled()

Is this state enabled

public isEnabled() : bool
Return values
bool

setDefaultStates()

Set the default states

public static setDefaultStates(array<string|int, mixed> $defaultStates) : void
Parameters
$defaultStates : array<string|int, mixed>

setEnabled()

Set the state to whatever is required. Most commonly true

public setEnabled(bool $enabled) : void
Parameters
$enabled : bool

setStates()

Set states

public static setStates(array<string|int, mixed> $states) : void
Parameters
$states : array<string|int, mixed>
Tags
static

variants()

Returns an array of variants.

public static variants([bool $force = false ]) : array<string|int, mixed>
Parameters
$force : bool = false

Force updating the variants

Tags
static
throws
ReflectionException
Return values
array<string|int, mixed>
  • An array of (string)$variantClassName => (Object)$variantInstance pairs

withState()

Activate a site state for indexing

public static withState( $state) : void
Parameters
$state :
Tags
throws
ReflectionException

        
On this page

Search results