Passed
Push — master ( 782ed8...beb39c )
by Simon
06:43
created

SubsitesExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
c 0
b 0
f 0
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onBeforeInit() 0 3 1
A onAfterInit() 0 6 1
1
<?php
2
/**
3
 * Class SubsitesExtension|Firesphere\SolrSubsites\Extensions\SubsitesExtension Add Subsite filter field to the index
4
 *
5
 * @package Firesphere\SolrSubsites\Extensions
6
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
7
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
8
 */
9
10
namespace Firesphere\SolrSubsites\Extensions;
11
12
use Firesphere\SolrSearch\Indexes\BaseIndex;
13
use Firesphere\SolrSearch\States\SiteState;
14
use SilverStripe\Core\Extension;
15
16
/**
17
 * Class \Firesphere\SolrSubsites\Extensions\SubsitesExtension
18
 *
19
 * Add support for subsites in the Index for filtering
20
 *
21
 * @package Firesphere\SolrSearch\Subsites
22
 * @property BaseIndex|SubsitesExtension $owner
23
 */
24
class SubsitesExtension extends Extension
25
{
26
    public function onBeforeInit()
27
    {
28 2
        SiteState::addStates(['unfiltered']);
29
    }
30
31
    /**
32 2
     * Add the subsite ID for each page, if subsites is enabled.
33 2
     */
34 2
    public function onAfterInit()
35
    {
36
        // Add default support for Subsites.
37
        /** @var BaseIndex $owner */
38
        $owner = $this->owner;
39
        $owner->addFilterField('SubsiteID');
40
    }
41
}
42