GridFieldAddNewButtonOriginalPage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getHTMLFragments() 0 28 4
A BestParentPage() 0 4 1
1
<?php
2
3
/**
4
 * Provides the entry point to editing a single record presented by the
5
 * {@link GridField}.
6
 *
7
 * Doesn't show an edit view on its own or modifies the record, but rather
8
 * relies on routing conventions established in {@link getColumnContent()}.
9
 *
10
 * The default routing applies to the {@link GridFieldDetailForm} component,
11
 * which has to be added separately to the {@link GridField} configuration.
12
 *
13
 * @package forms
14
 * @subpackage fields-gridfield
15
 */
16
class GridFieldAddNewButtonOriginalPage extends GridFieldAddNewButton
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    public function getHTMLFragments($gridField)
19
    {
20
        $singleton = singleton($gridField->getModelClass());
21
22
        if (!$singleton->canCreate()) {
23
            return array();
24
        }
25
26
        if (!$this->buttonName) {
27
            // provide a default button name, can be changed by calling {@link setButtonName()} on this component
28
            $objectName = $singleton->i18n_singular_name();
29
            $this->buttonName = _t('GridField.Add_USING_PAGES_SECTION', 'Add {name} using pages section', array('name' => $objectName));
0 ignored issues
show
Documentation introduced by
array('name' => $objectName) is of type array<string,?,{"name":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
        }
31
32
        $getSegment = "";
33
        if ($page = $this->BestParentPage()) {
34
            $getSegment = "?ParentID=".$page->ID;
35
        }
36
37
        $data = new ArrayData(array(
38
            'NewLink' => "/admin/".Config::inst()->get("CMSPageAddController_Products", "url_segment")."/".$getSegment,
39
            'ButtonName' => $this->buttonName,
40
        ));
41
42
        return array(
43
            $this->targetFragment => $data->renderWith('GridFieldAddNewbutton'),
44
        );
45
    }
46
47
48
    /**
49
     * finds the most likely root parent for the shop
50
     *
51
     * @return SiteTree | NULL
52
     */
53
    public function BestParentPage()
54
    {
55
        return SiteTree::get()->filter("ParentID", 0)->First();
56
    }
57
}
58