Passed
Push — master ( 2f8fac...1d731f )
by
unknown
02:40
created
src/Model/QuickLink.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -11,117 +11,117 @@
 block discarded – undo
11 11
 
12 12
 class Quicklink extends DataObject
13 13
 {
14
-    private static $db = [
15
-        'Name' => 'Varchar(255)',
16
-        'ExternalLink' => 'Varchar(255)',
17
-        'SortOrder' => 'Int',
18
-    ];
19
-
20
-    private static $has_one = [
21
-        'Parent' => BaseHomePage::class,
22
-        'InternalLink' => SiteTree::class,
23
-    ];
24
-
25
-    private static $summary_fields = [
26
-        'Name' => 'Name',
27
-        'InternalLink.Title' => 'Internal Link',
28
-        'ExternalLink' => 'External Link',
29
-    ];
30
-
31
-    private static $table_name = 'Quicklink';
32
-
33
-    public function fieldLabels($includerelations = true)
34
-    {
35
-        $labels = parent::fieldLabels($includerelations);
36
-        $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name');
37
-        $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link');
38
-        $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order');
39
-        $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent');
40
-        $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link');
41
-
42
-        return $labels;
43
-    }
44
-
45
-    public function getLink()
46
-    {
47
-        if ($this->ExternalLink) {
48
-            $url = parse_url($this->ExternalLink);
49
-
50
-            // if no scheme set in the link, default to http
51
-            if (!isset($url['scheme'])) {
52
-                return 'http://' . $this->ExternalLink;
53
-            }
54
-
55
-            return $this->ExternalLink;
56
-        } elseif ($this->InternalLinkID) {
57
-            return $this->InternalLink()->Link();
58
-        }
59
-    }
60
-
61
-    public function canCreate($member = null, $context = [])
62
-    {
63
-        return $this->Parent()->canCreate($member, $context);
64
-    }
65
-
66
-    public function canEdit($member = null)
67
-    {
68
-        return $this->Parent()->canEdit($member);
69
-    }
70
-
71
-    public function canDelete($member = null)
72
-    {
73
-        return $this->Parent()->canDelete($member);
74
-    }
75
-
76
-    public function canView($member = null)
77
-    {
78
-        return $this->Parent()->canView($member);
79
-    }
80
-
81
-    public function getCMSFields()
82
-    {
83
-        $fields = parent::getCMSFields();
84
-
85
-        $fields->removeByName('ParentID');
86
-
87
-        $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink');
88
-
89
-        $fields->removeByName('ExternalLink');
90
-        $fields->removeByName('InternalLinkID');
91
-        $fields->removeByName('SortOrder');
92
-        $externalLinkField->addExtraClass('noBorder');
93
-
94
-        $fields->addFieldToTab('Root.Main', CompositeField::create(
95
-            array(
96
-                TreeDropdownField::create(
97
-                    'InternalLinkID',
98
-                    $this->fieldLabel('InternalLinkID'),
99
-                    SiteTree::class
100
-                ),
101
-                $externalLinkField,
102
-                $wrap = CompositeField::create(
103
-                    $extraLabel = LiteralField::create(
104
-                        'NoteOverride',
105
-                        sprintf('<div class="message good notice">%s</div>', _t(
106
-                            __CLASS__ . '.Note',
107
-                            'Note: If you specify an External Link, the Internal Link will be ignored.'
108
-                        ))
109
-                    )
110
-                )
111
-            )
112
-        ));
113
-        $fields->insertBefore(
114
-            'Name',
115
-            LiteralField::create(
116
-                'Note',
117
-                sprintf('<p>%s</p>', _t(
118
-                    __CLASS__ . '.Note2',
119
-                    'Use this to specify a link to a page either on this site '
120
-                        . '(Internal Link) or another site (External Link).'
121
-                ))
122
-            )
123
-        );
124
-
125
-        return $fields;
126
-    }
14
+	private static $db = [
15
+		'Name' => 'Varchar(255)',
16
+		'ExternalLink' => 'Varchar(255)',
17
+		'SortOrder' => 'Int',
18
+	];
19
+
20
+	private static $has_one = [
21
+		'Parent' => BaseHomePage::class,
22
+		'InternalLink' => SiteTree::class,
23
+	];
24
+
25
+	private static $summary_fields = [
26
+		'Name' => 'Name',
27
+		'InternalLink.Title' => 'Internal Link',
28
+		'ExternalLink' => 'External Link',
29
+	];
30
+
31
+	private static $table_name = 'Quicklink';
32
+
33
+	public function fieldLabels($includerelations = true)
34
+	{
35
+		$labels = parent::fieldLabels($includerelations);
36
+		$labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name');
37
+		$labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link');
38
+		$labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order');
39
+		$labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent');
40
+		$labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link');
41
+
42
+		return $labels;
43
+	}
44
+
45
+	public function getLink()
46
+	{
47
+		if ($this->ExternalLink) {
48
+			$url = parse_url($this->ExternalLink);
49
+
50
+			// if no scheme set in the link, default to http
51
+			if (!isset($url['scheme'])) {
52
+				return 'http://' . $this->ExternalLink;
53
+			}
54
+
55
+			return $this->ExternalLink;
56
+		} elseif ($this->InternalLinkID) {
57
+			return $this->InternalLink()->Link();
58
+		}
59
+	}
60
+
61
+	public function canCreate($member = null, $context = [])
62
+	{
63
+		return $this->Parent()->canCreate($member, $context);
64
+	}
65
+
66
+	public function canEdit($member = null)
67
+	{
68
+		return $this->Parent()->canEdit($member);
69
+	}
70
+
71
+	public function canDelete($member = null)
72
+	{
73
+		return $this->Parent()->canDelete($member);
74
+	}
75
+
76
+	public function canView($member = null)
77
+	{
78
+		return $this->Parent()->canView($member);
79
+	}
80
+
81
+	public function getCMSFields()
82
+	{
83
+		$fields = parent::getCMSFields();
84
+
85
+		$fields->removeByName('ParentID');
86
+
87
+		$externalLinkField = $fields->fieldByName('Root.Main.ExternalLink');
88
+
89
+		$fields->removeByName('ExternalLink');
90
+		$fields->removeByName('InternalLinkID');
91
+		$fields->removeByName('SortOrder');
92
+		$externalLinkField->addExtraClass('noBorder');
93
+
94
+		$fields->addFieldToTab('Root.Main', CompositeField::create(
95
+			array(
96
+				TreeDropdownField::create(
97
+					'InternalLinkID',
98
+					$this->fieldLabel('InternalLinkID'),
99
+					SiteTree::class
100
+				),
101
+				$externalLinkField,
102
+				$wrap = CompositeField::create(
103
+					$extraLabel = LiteralField::create(
104
+						'NoteOverride',
105
+						sprintf('<div class="message good notice">%s</div>', _t(
106
+							__CLASS__ . '.Note',
107
+							'Note: If you specify an External Link, the Internal Link will be ignored.'
108
+						))
109
+					)
110
+				)
111
+			)
112
+		));
113
+		$fields->insertBefore(
114
+			'Name',
115
+			LiteralField::create(
116
+				'Note',
117
+				sprintf('<p>%s</p>', _t(
118
+					__CLASS__ . '.Note2',
119
+					'Use this to specify a link to a page either on this site '
120
+						. '(Internal Link) or another site (External Link).'
121
+				))
122
+			)
123
+		);
124
+
125
+		return $fields;
126
+	}
127 127
 }
Please login to merge, or discard this patch.