From 715be15a4d331dbd79efbd136c06af5ac050b3f3 Mon Sep 17 00:00:00 2001 From: madmatt Date: Mon, 28 Sep 2015 11:19:40 +1300 Subject: [PATCH] ENHANCEMENT: Add 'HideLabel' field for EditableLiteralField objects --- .../model/editableformfields/EditableLiteralField.php | 9 +++++++-- docs/en/user-documentation.md | 4 ++++ tests/EditableLiteralFieldTest.php | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/code/model/editableformfields/EditableLiteralField.php b/code/model/editableformfields/EditableLiteralField.php index 4da00d3..595e957 100644 --- a/code/model/editableformfields/EditableLiteralField.php +++ b/code/model/editableformfields/EditableLiteralField.php @@ -31,7 +31,8 @@ class EditableLiteralField extends EditableFormField { private static $db = array( 'Content' => 'HTMLText', // From CustomSettings - 'HideFromReports' => 'Boolean(0)' // from CustomSettings + 'HideFromReports' => 'Boolean(0)', // from CustomSettings + 'HideLabel' => 'Boolean(0)' ); private static $defaults = array( @@ -103,6 +104,10 @@ class EditableLiteralField extends EditableFormField { CheckboxField::create( 'HideFromReports', _t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?') + ), + CheckboxField::create( + 'HideLabel', + _t('EditableLiteralField.HIDELABEL', "Hide 'Title' label on frontend?") ) )); @@ -113,7 +118,7 @@ class EditableLiteralField extends EditableFormField { // Build label and css classes $label = ''; $classes = $this->ExtraClass; - if(empty($this->Title)) { + if(empty($this->Title) || $this->HideLabel) { $classes .= " nolabel"; } else { $label = ""; diff --git a/docs/en/user-documentation.md b/docs/en/user-documentation.md index 0ae581e..863978d 100644 --- a/docs/en/user-documentation.md +++ b/docs/en/user-documentation.md @@ -132,6 +132,10 @@ You can edit the HTML blog from the "Show options" link. If you do not check the "Hide from reports" checkbox then this field will be displayed in submission reports. +If you check the "Hide 'Title' label on frontend" checkbox then the title of this field +will be hidden on the form. This is useful when you want to output specific HTML code and +add your own headings within the content of this field. + Note: Take care not to allow input from unauthorised sources or users, as custom script or code could be injected into your form. diff --git a/tests/EditableLiteralFieldTest.php b/tests/EditableLiteralFieldTest.php index 9a565be..85508df 100644 --- a/tests/EditableLiteralFieldTest.php +++ b/tests/EditableLiteralFieldTest.php @@ -35,4 +35,15 @@ class EditableLiteralFieldTest extends SapphireTest { $field->setContent($rawContent); $this->assertEquals($rawContent, $field->getContent()); } + + public function testHideLabel() { + $field = new EditableLiteralField(array( + 'Title' => 'Test label' + )); + + $this->assertContains('Test label', $field->getFormField()->Field()); + + $field->HideLabel = true; + $this->assertNotContains('Test label', $field->getFormField()->Field()); + } }