sunnysideup /
silverstripe-cms-niceties
| 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\Core\Injector\Injector; |
||||||
| 9 | use SilverStripe\Forms\HTMLReadonlyField; |
||||||
| 10 | use Sunnysideup\CmsEditLinkField\Api\CMSEditLinkAPI; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 11 | |||||||
| 12 | trait CMSNicetiesTraitForCMSLinks |
||||||
| 13 | { |
||||||
| 14 | public function CMSEditLink() |
||||||
| 15 | { |
||||||
| 16 | if ($this instanceof SiteTree) { |
||||||
| 17 | return parent::CMSEditLink(); |
||||||
| 18 | } |
||||||
| 19 | return CMSEditLinkAPI::find_edit_link_for_object($this); |
||||||
| 20 | } |
||||||
| 21 | |||||||
| 22 | public function CMSEditLinkLimited(): string |
||||||
| 23 | { |
||||||
| 24 | return CMSEditLinkAPI::find_edit_link_for_object($this); |
||||||
| 25 | } |
||||||
| 26 | |||||||
| 27 | public function CMSEditLinkField(string $relName, string $name = ''): HTMLReadonlyField |
||||||
| 28 | { |
||||||
| 29 | $obj = $this->{$relName}(); |
||||||
| 30 | if ($name === '' || $name === '0') { |
||||||
| 31 | $nameOptions = $this->fieldLabels(); |
||||||
|
0 ignored issues
–
show
It seems like
fieldLabels() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 32 | $name = $nameOptions[$relName] ?? $nameOptions[$relName . 'ID'] ?? 'error'; |
||||||
| 33 | } |
||||||
| 34 | |||||||
| 35 | if ($obj && $obj->exists()) { |
||||||
| 36 | $value = '<a href="' . $obj->CMSEditLink() . '">' . $obj->getTitle() . '</a>'; |
||||||
| 37 | } else { |
||||||
| 38 | $value = '<em>(none)</em>'; |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | return HTMLReadonlyField::create( |
||||||
| 42 | $relName . 'Link', |
||||||
| 43 | $name, |
||||||
| 44 | $value |
||||||
| 45 | ); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | public function CMSAddLink(): string |
||||||
| 49 | { |
||||||
| 50 | return CMSEditLinkAPI::find_add_link_for_object($this->ClassName); |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | public function CMSListLink(): string |
||||||
| 54 | { |
||||||
| 55 | $controller = $this->myModelAdminController(); |
||||||
| 56 | if ($controller) { |
||||||
| 57 | return $controller->getLinkForModelClass($this->ClassName); |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | return '404-cms-list-link-not-found'; |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | /** |
||||||
| 64 | * @return null|ModelAdmin |
||||||
| 65 | */ |
||||||
| 66 | protected function myModelAdminController() |
||||||
| 67 | { |
||||||
| 68 | $modelAdminClassName = $this->Config()->get('primary_model_admin_class'); |
||||||
|
0 ignored issues
–
show
It seems like
Config() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 69 | $obj = null; |
||||||
| 70 | if ($modelAdminClassName) { |
||||||
| 71 | /** @var null|ModelAdmin $obj */ |
||||||
| 72 | $obj = Injector::inst()->get($modelAdminClassName); |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | return $obj; |
||||||
| 76 | } |
||||||
| 77 | |||||||
| 78 | /** |
||||||
| 79 | * Sanitise a model class' name for inclusion in a link. |
||||||
| 80 | */ |
||||||
| 81 | protected function sanitisedClassName(): string |
||||||
| 82 | { |
||||||
| 83 | $className = (string) $this->hasMethod('classNameForModelAdmin') !== '' && (string) $this->hasMethod('classNameForModelAdmin') !== '0' ? $this->classNameForModelAdmin() : $this->ClassName; |
||||||
|
0 ignored issues
–
show
It seems like
classNameForModelAdmin() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
hasMethod() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 84 | |||||||
| 85 | return str_replace('\\', '-', $className); |
||||||
| 86 | } |
||||||
| 87 | } |
||||||
| 88 |
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