Completed
Push — master ( 1f0706...385015 )
by Franco
15s queued 10s
created

DMSGridFieldAddNewButton::getPageId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class DMSGridFieldAddNewButton extends GridFieldAddNewButton implements GridField_HTMLProvider
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...
4
{
5
    /**
6
     * The page ID that the document should be attached to. Used in the GridField for Documents in a Page.
7
     *
8
     * @var int
9
     */
10
    protected $pageId;
11
12
    /**
13
     * Overriding the parent method to change the template that the DMS add button will be rendered with
14
     *
15
     * @param  GridField $gridField
16
     * @return array
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', 'Add {name}', 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
        $link = singleton('DMSDocumentAddController')->Link();
33
        if ($this->getPageId()) {
34
            $link = Controller::join_links($link, '?ID=' . $this->getPageId());
35
        }
36
37
        $data = new ArrayData(array(
38
            'NewLink' => $link,
39
            'ButtonName' => $this->buttonName,
40
        ));
41
42
        return array(
43
            $this->targetFragment => $data->renderWith('DMSGridFieldAddNewButton'),
44
        );
45
    }
46
47
    /**
48
     * Set the page ID that this document should be attached to
49
     *
50
     * @param  int $id
51
     * @return $this
52
     */
53
    public function setPageId($id)
54
    {
55
        $this->pageId = $id;
56
        return $this;
57
    }
58
59
    /**
60
     * Get the page ID that this document should be attached to
61
     *
62
     * @return int
63
     */
64
    public function getPageId()
65
    {
66
        return $this->pageId;
67
    }
68
}
69