Completed
Pull Request — master (#10)
by Franco
02:00
created

DMSDocumentCartCheckoutPage::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
/**
3
 * @property Text $ThanksMessage
4
 * @property Int  $CartEmailRecipientID
5
 *
6
 * @method Member CartEmailRecipient
7
 */
8
class DMSDocumentCartCheckoutPage extends Page
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...
9
{
10
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
        'ThanksMessage' => 'Text',
12
    );
13
14
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
        'CartEmailRecipient'     => 'Member'
16
    );
17
18
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'URLSegment'  => 'checkout',
20
        'ShowInMenus' => false,
21
    );
22
23
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
24
    {
25
        $fields = parent::getCMSFields();
26
        $recipientDropDown = DropdownField::create(
27
            'CartEmailRecipientID',
28
            _t('DMSDocumentCartCheckoutPage.CART_RECIPIENT', 'Account to receive document print requests'),
29
            Member::get()->Map()->toArray()
30
        )->setEmptyString(_t(
31
            'DMSDocumentCartCheckoutPage.CART_RECIPIENT_EMPTY_STRING',
32
            'Select a member'
33
        ));
34
        $fields->insertBefore('Content', $recipientDropDown);
35
36
        $fields->insertBefore(
37
            'Content',
38
            TextareaField::create(
39
                'ThanksMessage',
40
                _t('DMSDocumentCartCheckoutPage.THANK_YOU_MESSAGE', 'Thank you message')
41
            )
42
        );
43
44
        $fields->removeFieldFromTab('Root', 'Document Sets (' . $this->owner->DocumentSets()->count() . ')');
45
46
        return $fields;
47
    }
48
    /**
49
     * Automatically create a CheckoutPage if one is not found
50
     * on the site at the time the database is built (dev/build).
51
     */
52
    public function requireDefaultRecords()
53
    {
54
        parent::requireDefaultRecords();
55
56
        if (!SiteTree::get_one($this->class)) {
57
            /** @var DMSDocumentCartCheckoutPage $page */
58
            $page = self::create();
59
            $page->Title = 'Request a printed copy';
60
            $page->MenuTitle = 'Document Cart Checkout';
61
            $page->Content = '';
62
            $page->URLSegment = 'checkout';
63
            $page->ShowInMenus = 0;
64
            $page->ThanksMessage = 'Thanks for your request.';
65
            $page->write();
66
            $page->publish('Stage', 'Live');
67
            $page->flushCache();
68
            DB::alteration_message(
69
                _t(
70
                    'DMSDocumentCartCheckoutPage.ALTERATION_MESSAGE',
71
                    'Document Cart Checkout page \'Request a printed copy\' created'
72
                ),
73
                'created'
74
            );
75
        }
76
    }
77
}
78