Completed
Push — master ( 780648...a93e4f )
by Daniel
06:19
created

AnchorLinkFormFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormFields() 0 15 1
A getRequiredContext() 0 4 1
1
<?php
2
3
namespace SilverStripe\CMS\Forms;
4
5
class AnchorLinkFormFactory extends InternalLinkFormFactory
6
{
7
    protected function getFormFields($controller, $name, $context)
8
    {
9
        $fields = parent::getFormFields($controller, $name, $context);
10
11
        // Ensure current page is selected
12
        $pageIDField = $fields->dataFieldByName('PageID');
13
        $pageIDField->setValue((int)$context['PageID']);
14
15
        // Get anchor selector field
16
        $fields->insertAfter(
17
            'PageID',
18
            AnchorSelectorField::create('Anchor', _t(__CLASS__.'.ANCHORVALUE', 'Anchor'))
19
        );
20
        return $fields;
21
    }
22
23
    public function getRequiredContext()
24
    {
25
        return array_merge(parent::getRequiredContext(), [ 'PageID' ]);
26
    }
27
}
28