Completed
Pull Request — master (#518)
by Sam
34:41
created

getCanCreateContext()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
1
<?php
2
3
use SilverStripe\Control\Session;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use SilverStripe\Forms\GridField\GridFieldConfig;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldConfig.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use SilverStripe\Forms\GridField\GridFieldButtonRow;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldButtonRow.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldToolbarHeader.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDeleteAction.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use SilverStripe\Forms\DropdownField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DropdownField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use SilverStripe\Forms\TextField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, TextField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use SilverStripe\Forms\TabSet;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, TabSet.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use SilverStripe\View\Requirements;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Requirements.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use SilverStripe\ORM\ArrayList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ArrayList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
13
use SilverStripe\Forms\FieldList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FieldList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use SilverStripe\Forms\FieldGroup;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FieldGroup.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use SilverStripe\Forms\CheckboxField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CheckboxField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HTMLEditorField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use SilverStripe\Forms\TextareaField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, TextareaField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use SilverStripe\Forms\LiteralField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LiteralField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use SilverStripe\Forms\GridField\GridField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use SilverStripe\Control\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Controller.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use SilverStripe\CMS\Controllers\CMSMain;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CMSMain.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
use SilverStripe\Assets\FileFinder;
23
use SilverStripe\ORM\DataObject;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DataObject.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
25
26
/**
27
 * A Form can have multiply members / emails to email the submission
28
 * to and custom subjects
29
 *
30
 * @package userforms
31
 */
32
class UserDefinedForm_EmailRecipient extends DataObject
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...
33
{
34
35
    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...
36
        'EmailAddress' => 'Varchar(200)',
37
        'EmailSubject' => 'Varchar(200)',
38
        'EmailFrom' => 'Varchar(200)',
39
        'EmailReplyTo' => 'Varchar(200)',
40
        'EmailBody' => 'Text',
41
        'EmailBodyHtml' => 'HTMLText',
42
        'EmailTemplate' => 'Varchar',
43
        'SendPlain' => 'Boolean',
44
        'HideFormData' => 'Boolean',
45
        'CustomRulesCondition' => 'Enum("And,Or")'
46
    );
47
48
    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...
49
        'Form' => 'UserDefinedForm',
50
        'SendEmailFromField' => 'EditableFormField',
51
        'SendEmailToField' => 'EditableFormField',
52
        'SendEmailSubjectField' => 'EditableFormField'
53
    );
54
55
    private static $has_many = array(
0 ignored issues
show
Unused Code introduced by
The property $has_many 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...
56
        'CustomRules' => 'UserDefinedForm_EmailRecipientCondition'
57
    );
58
59
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields 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...
60
        'EmailAddress',
61
        'EmailSubject',
62
        'EmailFrom'
63
    );
64
65
    /**
66
     * Setting this to true will allow you to select "risky" fields as
67
     * email recipient, such as free-text entry fields.
68
     *
69
     * It's advisable to leave this off.
70
     *
71
     * @config
72
     * @var bool
73
     */
74
    private static $allow_unbound_recipient_fields = false;
0 ignored issues
show
Unused Code introduced by
The property $allow_unbound_recipient_fields 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...
75
76
    public function summaryFields()
77
    {
78
        $fields = parent::summaryFields();
79
        if (isset($fields['EmailAddress'])) {
80
            $fields['EmailAddress'] = _t('UserDefinedForm.EMAILADDRESS', 'SilverStripe\\Control\\Email\\Email');
81
        }
82
        if (isset($fields['EmailSubject'])) {
83
            $fields['EmailSubject'] = _t('UserDefinedForm.EMAILSUBJECT', 'Subject');
84
        }
85
        if (isset($fields['EmailFrom'])) {
86
            $fields['EmailFrom'] = _t('UserDefinedForm.EMAILFROM', 'From');
87
        }
88
        return $fields;
89
    }
90
91
    /**
92
     * Get instance of UserDefinedForm when editing in getCMSFields
93
     *
94
     * @return UserDefinedFrom
95
     */
96
    protected function getFormParent()
97
    {
98
        $formID = $this->FormID
99
            ? $this->FormID
100
            : Session::get('CMSMain.currentPage');
101
        return UserDefinedForm::get()->byID($formID);
102
    }
103
104
    public function getTitle()
105
    {
106
        if ($this->EmailAddress) {
107
            return $this->EmailAddress;
108
        }
109
        if ($this->EmailSubject) {
110
            return $this->EmailSubject;
111
        }
112
        return parent::getTitle();
113
    }
114
115
    /**
116
     * Generate a gridfield config for editing filter rules
117
     *
118
     * @return GridFieldConfig
119
     */
120
    protected function getRulesConfig()
121
    {
122
        $formFields = $this->getFormParent()->Fields();
123
124
        $config = GridFieldConfig::create()
125
            ->addComponents(
126
                new GridFieldButtonRow('before'),
127
                new GridFieldToolbarHeader(),
128
                new GridFieldAddNewInlineButton(),
129
                new GridFieldDeleteAction(),
130
                $columns = new GridFieldEditableColumns()
131
            );
132
133
        $columns->setDisplayFields(array(
134
            'ConditionFieldID' => function ($record, $column, $grid) use ($formFields) {
0 ignored issues
show
Unused Code introduced by
The parameter $grid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
135
                return DropdownField::create($column, false, $formFields->map('ID', 'Title'));
136
            },
137
            'ConditionOption' => function ($record, $column, $grid) {
0 ignored issues
show
Unused Code introduced by
The parameter $grid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
138
                $options = UserDefinedForm_EmailRecipientCondition::config()->condition_options;
139
                return DropdownField::create($column, false, $options);
140
            },
141
            'ConditionValue' => function ($record, $column, $grid) {
0 ignored issues
show
Unused Code introduced by
The parameter $grid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
                return TextField::create($column);
143
            }
144
        ));
145
146
        return $config;
147
    }
148
149
    /**
150
     * @return FieldList
151
     */
152
    public function getCMSFields()
153
    {
154
        Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js');
155
156
        // Determine optional field values
157
        $form = $this->getFormParent();
158
159
        // predefined choices are also candidates
160
        $multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', $form->ID);
161
162
        // if they have email fields then we could send from it
163
        $validEmailFromFields = EditableEmailField::get()->filter('ParentID', $form->ID);
164
165
        // For the subject, only one-line entry boxes make sense
166
        $validSubjectFields = ArrayList::create(
167
            EditableTextField::get()
168
                ->filter('ParentID', $form->ID)
169
                ->exclude('Rows:GreaterThan', 1)
170
                ->toArray()
171
        );
172
        $validSubjectFields->merge($multiOptionFields);
173
174
175
        // Check valid email-recipient fields
176
        if ($this->config()->allow_unbound_recipient_fields) {
177
            // To address can only be email fields or multi option fields
178
            $validEmailToFields = ArrayList::create($validEmailFromFields->toArray());
179
            $validEmailToFields->merge($multiOptionFields);
180
        } else {
181
            // To address cannot be unbound, so restrict to pre-defined lists
182
        $validEmailToFields = $multiOptionFields;
183
        }
184
185
        // Build fieldlist
186
        $fields = FieldList::create(TabSet::create('Root')->addExtraClass('EmailRecipientForm'));
187
188
        // Configuration fields
189
        $fields->addFieldsToTab('Root.EmailDetails', array(
190
            // Subject
191
            FieldGroup::create(
192
                TextField::create('EmailSubject', _t('UserDefinedForm.TYPESUBJECT', 'Type subject'))
193
                    ->setAttribute('style', 'min-width: 400px;'),
194
                DropdownField::create(
195
                    'SendEmailSubjectFieldID',
196
                    _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'),
197
                    $validSubjectFields->map('ID', 'Title')
198
                )->setEmptyString('')
199
            )
200
                ->setTitle(_t('UserDefinedForm.EMAILSUBJECT', 'Email subject')),
201
202
            // To
203
            FieldGroup::create(
204
                TextField::create('EmailAddress', _t('UserDefinedForm.TYPETO', 'Type to address'))
205
                    ->setAttribute('style', 'min-width: 400px;'),
206
                DropdownField::create(
207
                    'SendEmailToFieldID',
208
                    _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'),
209
                    $validEmailToFields->map('ID', 'Title')
210
                )->setEmptyString(' ')
211
            )
212
                ->setTitle(_t('UserDefinedForm.SENDEMAILTO', 'Send email to'))
213
                ->setDescription(_t(
214
                    'UserDefinedForm.SENDEMAILTO_DESCRIPTION',
215
                    'You may enter multiple email addresses as a comma separated list.'
216
                )),
217
218
219
            // From
220
            TextField::create('EmailFrom', _t('UserDefinedForm.FROMADDRESS', 'Send email from'))
221
                ->setDescription(_t(
222
                    'UserDefinedForm.EmailFromContent',
223
                    "The from address allows you to set who the email comes from. On most servers this ".
224
                    "will need to be set to an email address on the same domain name as your site. ".
225
                    "For example on yoursite.com the from address may need to be [email protected]. ".
226
                    "You can however, set any email address you wish as the reply to address."
227
                )),
228
229
230
            // Reply-To
231
            FieldGroup::create(
232
                TextField::create('EmailReplyTo', _t('UserDefinedForm.TYPEREPLY', 'Type reply address'))
233
                    ->setAttribute('style', 'min-width: 400px;'),
234
                DropdownField::create(
235
                    'SendEmailFromFieldID',
236
                    _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'),
237
                    $validEmailFromFields->map('ID', 'Title')
238
                )->setEmptyString(' ')
239
            )
240
                ->setTitle(_t('UserDefinedForm.REPLYADDRESS', 'Email for reply to'))
241
                ->setDescription(_t(
242
                    'UserDefinedForm.REPLYADDRESS_DESCRIPTION',
243
                    'The email address which the recipient is able to \'reply\' to.'
244
                ))
245
        ));
246
        
247
        $fields->fieldByName('Root.EmailDetails')->setTitle(_t('UserDefinedForm_EmailRecipient.EMAILDETAILSTAB', 'Email Details'));
248
249
        // Only show the preview link if the recipient has been saved.
250
        if (!empty($this->EmailTemplate)) {
251
            $preview = sprintf(
252
                '<p><a href="%s" target="_blank" class="ss-ui-button">%s</a></p><em>%s</em>',
253
                "admin/pages/edit/EditForm/field/EmailRecipients/item/{$this->ID}/preview",
254
                _t('UserDefinedForm.PREVIEW_EMAIL', 'Preview email'),
255
                _t('UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', 'Note: Unsaved changes will not appear in the preview.')
256
            );
257
        } else {
258
            $preview = sprintf(
259
                '<em>%s</em>',
260
                _t(
261
                    'UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE',
262
                    'You can preview this email once you have saved the Recipient.'
263
                )
264
            );
265
        }
266
267
        // Email templates
268
        $fields->addFieldsToTab('Root.EmailContent', array(
269
            CheckboxField::create('HideFormData', _t('UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?')),
270
            CheckboxField::create(
271
                'SendPlain',
272
                _t('UserDefinedForm.SENDPLAIN', 'Send email as plain text? (HTML will be stripped)')
273
            ),
274
            DropdownField::create(
275
                'EmailTemplate',
276
                _t('UserDefinedForm.EMAILTEMPLATE', 'Email template'),
277
                $this->getEmailTemplateDropdownValues()
278
            )->addExtraClass('toggle-html-only'),
279
            HTMLEditorField::create('EmailBodyHtml', _t('UserDefinedForm.EMAILBODYHTML', 'Body'))
280
                ->addExtraClass('toggle-html-only'),
281
            TextareaField::create('EmailBody', _t('UserDefinedForm.EMAILBODY', 'Body'))
282
                ->addExtraClass('toggle-plain-only'),
283
            LiteralField::create(
284
                'EmailPreview',
285
                '<div id="EmailPreview" class="field toggle-html-only">' . $preview . '</div>'
286
            )
287
        ));
288
        
289
        $fields->fieldByName('Root.EmailContent')->setTitle(_t('UserDefinedForm_EmailRecipient.EMAILCONTENTTAB', 'Email Content'));
290
291
        // Custom rules for sending this field
292
        $grid = new GridField(
293
            "CustomRules",
294
            _t('EditableFormField.CUSTOMRULES', 'Custom Rules'),
295
            $this->CustomRules(),
296
            $this->getRulesConfig()
297
        );
298
        $grid->setDescription(_t(
299
            'UserDefinedForm.RulesDescription',
300
            'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.'
301
        ));
302
        $fields->addFieldsToTab('Root.CustomRules', array(
303
            new DropdownField(
304
                'CustomRulesCondition',
305
                _t('UserDefinedForm.SENDIF', 'Send condition'),
306
                array(
307
                    'Or' => _t('UserDefinedForm.SENDIFOR', 'Any conditions are true'),
308
                    'And' => _t('UserDefinedForm.SENDIFAND', 'All conditions are true')
309
                )
310
            ),
311
            $grid
312
        ));
313
        
314
        $fields->fieldByName('Root.CustomRules')->setTitle(_t('UserDefinedForm_EmailRecipient.CUSTOMRULESTAB', 'Custom Rules'));
315
316
        $this->extend('updateCMSFields', $fields);
317
        return $fields;
318
    }
319
320
    /**
321
     * Return whether a user can create an object of this type
322
     *
323
     * @param Member $member
324
     * @param array $context Virtual parameter to allow context to be passed in to check
325
     * @return bool
326
     */
327 View Code Duplication
    public function canCreate($member = null, $context = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
328
    {
329
        // Check parent page
330
        $parent = $this->getCanCreateContext($context);
331
        if ($parent) {
332
            return $parent->canEdit($member);
333
        }
334
335
        // Fall back to secure admin permissions
336
        return parent::canCreate($member);
337
    }
338
339
    /**
340
     * Helper method to check the parent for this object
341
     *
342
     * @param array $args List of arguments passed to canCreate
0 ignored issues
show
Bug introduced by
There is no parameter named $args. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
343
     * @return SiteTree Parent page instance
344
     */
345 View Code Duplication
    protected function getCanCreateContext($context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346
    {
347
        // Inspect second parameter to canCreate for a 'Parent' context
348
        if (isset($context['Form'])) {
349
            return $context['Form'];
350
        }
351
        // Hack in currently edited page if context is missing
352
        if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
0 ignored issues
show
Bug introduced by
The class SilverStripe\CMS\Controllers\CMSMain does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
353
            return Controller::curr()->currentPage();
354
        }
355
356
        // No page being edited
357
        return null;
358
    }
359
360
    /**
361
     * @param Member
362
     *
363
     * @return boolean
364
     */
365
    public function canView($member = null)
366
    {
367
        return $this->Form()->canView($member);
368
    }
369
370
    /**
371
     * @param Member
372
     *
373
     * @return boolean
374
     */
375
    public function canEdit($member = null)
376
    {
377
        return $this->Form()->canEdit($member);
378
    }
379
380
    /**
381
     * @param Member
382
     *
383
     * @return boolean
384
     */
385
    public function canDelete($member = null)
386
    {
387
        return $this->canEdit($member);
388
    }
389
390
    /*
391
     * Determine if this recipient may receive notifications for this submission
392
     *
393
     * @param array $data
394
     * @param Form $form
395
     * @return bool
396
     */
397
    public function canSend($data, $form)
398
    {
399
        // Skip if no rules configured
400
        $customRules = $this->CustomRules();
401
        if (!$customRules->count()) {
402
            return true;
403
        }
404
405
        // Check all rules
406
        $isAnd = $this->CustomRulesCondition === 'And';
407
        foreach ($customRules as $customRule) {
408
            $matches = $customRule->matches($data, $form);
409
            if ($isAnd && !$matches) {
410
                return false;
411
            }
412
            if (!$isAnd && $matches) {
413
                return true;
414
            }
415
        }
416
417
        // Once all rules are checked
418
        return $isAnd;
419
    }
420
421
    /**
422
     * Make sure the email template saved against the recipient exists on the file system.
423
     *
424
     * @param string
425
     *
426
     * @return boolean
427
     */
428
    public function emailTemplateExists($template = '')
429
    {
430
        $t = ($template ? $template : $this->EmailTemplate);
431
432
        return in_array($t, $this->getEmailTemplateDropdownValues());
433
    }
434
435
    /**
436
     * Get the email body for the current email format
437
     *
438
     * @return string
439
     */
440
    public function getEmailBodyContent()
441
    {
442
        return $this->SendPlain ? $this->EmailBody : $this->EmailBodyHtml;
443
    }
444
445
    /**
446
     * Gets a list of email templates suitable for populating the email template dropdown.
447
     *
448
     * @return array
449
     */
450
    public function getEmailTemplateDropdownValues()
451
    {
452
        $templates = array();
453
454
        $finder = new FileFinder();
455
        $finder->setOption('name_regex', '/^.*\.ss$/');
456
457
        $found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->email_template_directory);
458
459
        foreach ($found as $key => $value) {
460
            $template = pathinfo($value);
461
462
            $templates[$template['filename']] = $template['filename'];
463
        }
464
465
        return $templates;
466
    }
467
}
468