Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive hide form on pages #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Only:
Feedback:
extensions:
- FeedbackSiteTreeExtension
Page:
extensions:
- FeedbackPageExtension
17 changes: 17 additions & 0 deletions code/extensions/FeedbackPageExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
class FeedbackPageExtension extends DataExtension {
/**
* @var array
*/
public static $db = array(
'DisplayFeedback' => 'Enum("show,hide,inherit","inherit")',
);

public function updateSettingsFields(FieldList $fields) {
$feedback = new FieldGroup(
DropdownField::create('DisplayFeedback', '', singleton('Page')->dbObject('DisplayFeedback')->enumValues())
);

$fields->addFieldToTab("Root.Settings", $feedback->setTitle('Show feedback form?'));
}
}
26 changes: 26 additions & 0 deletions code/extensions/QuickFeedbackExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ class QuickFeedbackExtension extends DataExtension {
* @return Form
*/
public function QuickFeedbackForm() {

// if DisplayFeedback returns 'hide' then hide form
$page = $this->owner;

if ($page->DisplayFeedback == 'hide') {
return false;
}

$previous = null;

while ($page->hasMethod("Parent") && $parent = $page->Parent()) {
if ($previous && $previous->ID == $parent->ID) {
break;
}

$previous = $parent;

if ($page->DisplayFeedback == 'show') {
break;
}

if ($parent->DisplayFeedback == 'hide') {
return false;
}
}

$fields = FieldList::create(
LiteralField::create('RatingTitle', _t('QuickFeedback.Title', '<h4>Was this article helpful?</h4>')),
ButtonGroupField::create('Rating', '', array(
Expand Down