1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\ElementalSwitchTabs\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\LiteralField; |
6
|
|
|
use SilverStripe\ORM\DataExtension; |
7
|
|
|
|
8
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
9
|
|
|
|
10
|
|
|
class ElementalSwitchTabsExtension extends DataExtension |
11
|
|
|
{ |
12
|
|
|
public function getLinksField(string $nameOfTab, string $label) |
13
|
|
|
{ |
14
|
|
|
return LiteralField::create( |
15
|
|
|
'LinkToLink' . $nameOfTab, |
16
|
|
|
'<a href="#" onclick="' . $this->getJsFoTabSwitch($nameOfTab) . '">' . $label . '</a>' |
17
|
|
|
); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
protected function getJsFoTabSwitch(string $nameOfTab): string |
21
|
|
|
{ |
22
|
|
|
return <<<js |
23
|
|
|
if(jQuery(this).closest('div.element-editor__element').length > 0) { |
24
|
|
|
jQuery(this) |
25
|
|
|
.closest('div.element-editor__element') |
26
|
|
|
.find('button[name=\\'{$nameOfTab}\\']') |
27
|
|
|
.click(); |
28
|
|
|
} else { |
29
|
|
|
jQuery('li[aria-controls=\\'Root_{$nameOfTab}\\'] a').click(); |
30
|
|
|
} |
31
|
|
|
return false; |
32
|
|
|
js; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return BaseElement|null |
38
|
|
|
*/ |
39
|
|
|
public function PreviousBlock() |
40
|
|
|
{ |
41
|
|
|
if($this->exists()) { |
|
|
|
|
42
|
|
|
$parent = $this->getOwner()->Parent(); |
43
|
|
|
if($parent) { |
44
|
|
|
return BaseElement::get() |
45
|
|
|
->filter(['Sort:LessThanOrEqual' => $this->Sort]) |
|
|
|
|
46
|
|
|
->exclude(['ID' => $this->ID]) |
|
|
|
|
47
|
|
|
->sort(['Sort' => 'ASC']) |
48
|
|
|
->last(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return BaseElement|null |
55
|
|
|
*/ |
56
|
|
|
public function NextBlock() |
57
|
|
|
{ |
58
|
|
|
if($this->exists()) { |
59
|
|
|
$parent = $this->getOwner()->Parent(); |
60
|
|
|
if($parent) { |
61
|
|
|
return BaseElement::get() |
62
|
|
|
->filter(['Sort:GreaterThanOrEqual' => $this->Sort]) |
|
|
|
|
63
|
|
|
->exclude(['ID' => $this->ID]) |
|
|
|
|
64
|
|
|
->sort(['Sort' => 'ASC']) |
65
|
|
|
->first(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.