Completed
Pull Request — master (#10)
by Franco
01:57
created

requireDefaultRecords()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
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
        return $fields;
45
    }
46
    /**
47
     * Automatically create a CheckoutPage if one is not found
48
     * on the site at the time the database is built (dev/build).
49
     */
50
    public function requireDefaultRecords()
51
    {
52
        parent::requireDefaultRecords();
53
54
        if (!SiteTree::get_one($this->class)) {
55
            /** @var DMSDocumentCartCheckoutPage $page */
56
            $page = self::create();
57
            $page->Title = 'Request a printed copy';
58
            $page->MenuTitle = 'Document Cart Checkout';
59
            $page->Content = '';
60
            $page->URLSegment = 'checkout';
61
            $page->ShowInMenus = 0;
62
            $page->ThanksMessage = 'Thanks for your request.';
63
            $page->write();
64
            $page->publish('Stage', 'Live');
65
            $page->flushCache();
66
            DB::alteration_message(
67
                _t(
68
                    'DMSDocumentCartCheckoutPage.ALTERATION_MESSAGE',
69
                    'Document Cart Checkout page \'Request a printed copy\' created'
70
                ),
71
                'created'
72
            );
73
        }
74
    }
75
}
76