Skip to content

Commit

Permalink
Remove redundant phpcs rules, reduce some line lengths and use inject…
Browse files Browse the repository at this point in the history
…or to create checkbox fields
  • Loading branch information
robbieaverill committed Sep 24, 2018
1 parent 9f9dc67 commit 9a57c38
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
14 changes: 1 addition & 13 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</ruleset>
30 changes: 20 additions & 10 deletions src/Extensions/CommentsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ public function updateSettingsFields(FieldList $fields)

// 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')
)
Expand All @@ -180,16 +183,23 @@ public function updateSettingsFields(FieldList $fields)

// 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(
'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'
$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);
}
Expand Down
15 changes: 12 additions & 3 deletions src/Forms/CommentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ public function __construct($name, CommentingController $controller)
// 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)
),
Expand Down

0 comments on commit 9a57c38

Please sign in to comment.