Remove redundant phpcs rules, reduce some line lengths and use injector to create checkbox fields

This commit is contained in:
Robbie Averill 2018-09-24 18:04:17 +02:00
parent 9f9dc67950
commit 9a57c3802c
3 changed files with 33 additions and 26 deletions

View File

@ -6,17 +6,5 @@
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
</rule>
</ruleset>

View File

@ -157,13 +157,16 @@ class CommentsExtension extends DataExtension
// Check if enabled setting should be cms configurable
if ($this->owner->getCommentsOption('enabled_cms')) {
$options->push(new CheckboxField('ProvideComments', _t('SilverStripe\\Comments\\Model\\Comment.ALLOWCOMMENTS', 'Allow Comments')));
$options->push(CheckboxField::create('ProvideComments', _t(
'SilverStripe\\Comments\\Model\\Comment.ALLOWCOMMENTS',
'Allow Comments'
)));
}
// Check if we should require users to login to comment
if ($this->owner->getCommentsOption('require_login_cms')) {
$options->push(
new CheckboxField(
CheckboxField::create(
'CommentsRequireLogin',
_t('Comments.COMMENTSREQUIRELOGIN', 'Require login to comment')
)
@ -180,16 +183,23 @@ class CommentsExtension extends DataExtension
// Check if moderation should be enabled via cms configurable
if ($this->owner->getCommentsOption('require_moderation_cms')) {
$moderationField = new DropdownField('ModerationRequired', _t(__CLASS__ . '.COMMENTMODERATION', 'Comment Moderation'), array(
$moderationField = DropdownField::create(
'ModerationRequired',
_t(
__CLASS__ . '.COMMENTMODERATION',
'Comment Moderation'
),
[
'None' => _t(__CLASS__ . '.MODERATIONREQUIRED_NONE', 'No moderation required'),
'Required' => _t(__CLASS__ . '.MODERATIONREQUIRED_REQUIRED', 'Moderate all comments'),
'NonMembersOnly' => _t(
__CLASS__ . '.MODERATIONREQUIRED_NONMEMBERSONLY',
'Only moderate non-members'
),
));
]
);
if ($fields->hasTabSet()) {
$fields->addFieldsToTab('Root.Settings', $moderationField);
$fields->addFieldToTab('Root.Settings', $moderationField);
} else {
$fields->push($moderationField);
}

View File

@ -44,18 +44,27 @@ class CommentForm extends Form
// Email
EmailField::create(
'Email',
_t('SilverStripe\\Comments\\Controllers\\CommentingController.EMAILADDRESS', 'Your email address (will not be published)')
_t(
'SilverStripe\\Comments\\Controllers\\CommentingController.EMAILADDRESS',
'Your email address (will not be published)'
)
)
->setCustomValidationMessage($emailRequired)
->setAttribute('data-msg-required', $emailRequired)
->setAttribute('data-msg-email', $emailInvalid)
->setAttribute('data-rule-email', true),
// Url
TextField::create('URL', _t('SilverStripe\\Comments\\Controllers\\CommentingController.WEBSITEURL', 'Your website URL'))
TextField::create('URL', _t(
'SilverStripe\\Comments\\Controllers\\CommentingController.WEBSITEURL',
'Your website URL'
))
->setAttribute('data-msg-url', $urlInvalid)
->setAttribute('data-rule-url', true),
// Comment
TextareaField::create('Comment', _t('SilverStripe\\Comments\\Controllers\\CommentingController.COMMENTS', 'Comments'))
TextareaField::create('Comment', _t(
'SilverStripe\\Comments\\Controllers\\CommentingController.COMMENTS',
'Comments'
))
->setCustomValidationMessage($commentRequired)
->setAttribute('data-msg-required', $commentRequired)
),