|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\CMSNiceties\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Admin\ModelAdmin; |
|
6
|
|
|
// use SilverStripe\Forms\GridField\GridFieldArchiveAction; |
|
7
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
8
|
|
|
use SilverStripe\Control\Controller; |
|
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
10
|
|
|
use SilverStripe\Forms\HTMLReadonlyField; |
|
11
|
|
|
use Sunnysideup\CmsEditLinkField\Api\CMSEditLinkAPI; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
trait CMSNicetiesTraitForCMSLinks |
|
14
|
|
|
{ |
|
15
|
|
|
public function CMSEditLink(): string |
|
16
|
|
|
{ |
|
17
|
|
|
if ($this instanceof SiteTree) { |
|
18
|
|
|
return parent::CMSEditLink(); |
|
19
|
|
|
} |
|
20
|
|
|
return CMSEditLinkAPI::find_edit_link_for_object($this); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function CMSEditLinkLimited(): string |
|
24
|
|
|
{ |
|
25
|
|
|
return CMSEditLinkAPI::find_edit_link_for_object($this); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function CMSEditLinkField(string $relName, string $name = ''): HTMLReadonlyField |
|
29
|
|
|
{ |
|
30
|
|
|
$obj = $this->{$relName}(); |
|
31
|
|
|
if (!$name) { |
|
32
|
|
|
$nameOptions = $this->fieldLabels(); |
|
|
|
|
|
|
33
|
|
|
$name = $nameOptions[$relName] ?? $nameOptions[$relName . 'ID'] ?? 'error'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ($obj && $obj->exists()) { |
|
37
|
|
|
$value = '<a href="' . $obj->CMSEditLink() . '">' . $obj->getTitle() . '</a>'; |
|
38
|
|
|
} else { |
|
39
|
|
|
$value = '<em>(none)</em>'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return HTMLReadonlyField::create( |
|
43
|
|
|
$relName . 'Link', |
|
44
|
|
|
$name, |
|
45
|
|
|
$value |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function CMSAddLink(): string |
|
50
|
|
|
{ |
|
51
|
|
|
return CMSEditLinkAPI::find_add_link_for_object($this->ClassName); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function CMSListLink(): string |
|
55
|
|
|
{ |
|
56
|
|
|
$controller = $this->myModelAdminController(); |
|
57
|
|
|
if ($controller) { |
|
58
|
|
|
return Controller::join_links( |
|
59
|
|
|
$controller->Link(), |
|
60
|
|
|
$this->sanitisedClassName() |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return '404-cms-list-link-not-found'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return null|ModelAdmin |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function myModelAdminController() |
|
71
|
|
|
{ |
|
72
|
|
|
$modelAdminClassName = $this->Config()->get('primary_model_admin_class'); |
|
|
|
|
|
|
73
|
|
|
$obj = null; |
|
74
|
|
|
if ($modelAdminClassName) { |
|
75
|
|
|
/** @var null|ModelAdmin $obj */ |
|
76
|
|
|
$obj = Injector::inst()->get($modelAdminClassName); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $obj; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Sanitise a model class' name for inclusion in a link. |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function sanitisedClassName(): string |
|
86
|
|
|
{ |
|
87
|
|
|
$className = (string) $this->hasMethod('classNameForModelAdmin') ? $this->classNameForModelAdmin() : $this->ClassName; |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
return str_replace('\\', '-', $className); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths