1 | <?php |
||
2 | |||
3 | namespace DNADesign\ElementalList\Extension; |
||
4 | |||
5 | use DNADesign\Elemental\Models\BaseElement; |
||
6 | use DNADesign\ElementalList\Model\ElementList; |
||
7 | use SilverStripe\CMS\Controllers\CMSPageEditController; |
||
8 | use SilverStripe\Control\Controller; |
||
9 | use SilverStripe\Core\Extension; |
||
10 | |||
11 | /** |
||
12 | * Class BaseElementCMSEditLinkExtension |
||
13 | * |
||
14 | * BaseElement can be nested, CMSEditLink() needs to be updated to reflect that |
||
15 | * |
||
16 | * @property BaseElementCMSEditLinkExtension|$this $owner |
||
17 | * @package DNADesign\ElementalList\Extension |
||
18 | */ |
||
19 | class BaseElementCMSEditLinkExtension extends Extension |
||
20 | { |
||
21 | /** |
||
22 | * @param string $link |
||
23 | */ |
||
24 | public function updateCMSEditLink(&$link) |
||
25 | { |
||
26 | /** @var $owner BaseElement */ |
||
27 | $owner = $this->owner; |
||
28 | |||
29 | $relationName = $owner->getAreaRelationName(); |
||
30 | $page = $owner->getPage(true); |
||
0 ignored issues
–
show
|
|||
31 | |||
32 | if (!$page) { |
||
0 ignored issues
–
show
The expression
$page of type null|false is loosely compared to false ; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.
If an expression can have both $a = canBeFalseAndNull();
// Instead of
if ( ! $a) { }
// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
|
|||
33 | return; |
||
34 | } |
||
35 | |||
36 | if ($page instanceof ElementList) { |
||
37 | // nested bock - we need to get edit link of parent block |
||
38 | $link = Controller::join_links( |
||
39 | $page->CMSEditLink(), |
||
40 | 'ItemEditForm/field/' . $page->getOwnedAreaRelationName() . '/item/', |
||
41 | $owner->ID |
||
42 | ); |
||
43 | |||
44 | // remove edit link from parent CMS link |
||
45 | $link = preg_replace('/\/item\/([\d]+)\/edit/', '/item/$1', $link); |
||
46 | } else { |
||
47 | // block is directly under a non-block object - we have reached the top of nesting chain |
||
48 | $link = Controller::join_links( |
||
49 | singleton(CMSPageEditController::class)->Link('EditForm'), |
||
50 | $page->ID, |
||
51 | 'field/' . $relationName . '/item/', |
||
52 | $owner->ID |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | $link = Controller::join_links( |
||
57 | $link, |
||
58 | 'edit' |
||
59 | ); |
||
60 | } |
||
61 | } |
||
62 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.