From 88ae66e186bbb30f0acef3d3bfea9e16f27fc29a Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 8 Jul 2021 11:34:55 -0400 Subject: [PATCH] Update CommentForm "normal" render to use custom defined classes that were previously only used by "threaded" render --- .../FieldtypeComments/CommentForm.php | 81 +++++++++++-------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php index 91a30186..3d680511 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php @@ -110,6 +110,7 @@ class CommentForm extends Wire implements CommentFormInterface { ), 'classes' => array( 'form' => '', + 'wrapper' => '', // when specified, wrapper inside
...
'label' => '', 'labelSpan' => '', 'cite' => 'CommentFormCite {id}_cite', @@ -607,41 +608,52 @@ class CommentForm extends Wire implements CommentFormInterface { * */ protected function renderFormNormal($id, $class, $attrs, $labels, $inputValues) { + + $classes = $this->options['classes']; $tag = $this->options['inputWrapTag']; + $labelClass = $classes['label'] ? " class='$classes[label]'" : ""; + + foreach($classes as $k => $v) { + $classes[$k] = str_replace('{id}', $id, $v); + } + + $formClass = trim("$class $classes[form] CommentFormNormal"); + $form = - "\n
" . - "\n\t<$tag class='CommentFormCite {$id}_cite'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t" . - "\n\t<$tag class='CommentFormEmail {$id}_email'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t"; + "" . + ($classes['wrapper'] ? "
" : "") . + "<$tag class='$classes[cite]'>" . + "$labels[cite]" . + "" . + "" . + "<$tag class='$classes[email]'>" . + "$labels[email]" . + "" . + ""; if($this->commentsField && $this->commentsField->useWebsite && $this->commentsField->schemaVersion > 0) { $form .= - "\n\t<$tag class='CommentFormWebsite {$id}_website'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t"; + "<$tag class='$classes[website]'>" . + "$labels[website]" . + "" . + ""; } if($this->commentsField->useStars && $this->commentsField->schemaVersion > 5) { $commentStars = new CommentStars(); - $starsClass = 'CommentFormStars'; + $starsClass = $classes['stars']; if($this->commentsField->useStars > 1) { $starsNote = $labels['starsRequired']; - $starsClass .= ' CommentFormStarsRequired'; + $starsClass = trim("$starsClass $classes[starsRequired]"); } else { $starsNote = ''; } $form .= - "\n\t<$tag class='$starsClass {$id}_stars' data-note='$starsNote'>" . - ($labels['stars'] ? "\n\t\t" : "") . - "\n\t\t" . - "\n\t\t" . $commentStars->render(0, true) . - "\n\t"; + "<$tag class='$starsClass' data-note='$starsNote'>" . + ($labels['stars'] ? "$labels[stars]" : "") . + "" . + $commentStars->render(0, true) . + ""; } // do we need to show the honeypot field? @@ -650,23 +662,24 @@ class CommentForm extends Wire implements CommentFormInterface { $honeypotLabel = isset($labels[$honeypot]) ? $labels[$honeypot] : ''; $honeypotValue = isset($inputValues[$honeypot]) ? $inputValues[$honeypot] : ''; $form .= - "\n\t<$tag class='CommentFormHP {$id}_hp'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t"; + "<$tag class='$classes[honeypot]'>" . + "$honeypotLabel" . + "" . + ""; } $form .= - "\n\t<$tag class='CommentFormText {$id}_text'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t" . - $this->renderNotifyOptions() . - "\n\t<$tag class='CommentFormSubmit {$id}_submit'>" . - "\n\t\t" . - "\n\t\t" . - "\n\t" . - "\n"; + "<$tag class='$classes[text]'>" . + "$labels[text]" . + "" . + "" . + $this->renderNotifyOptions() . + "<$tag class='$classes[submit]'>" . + "" . + "" . + "" . + ($classes['wrapper'] ? "
" : "") . + ""; return $form; }