-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #5
- Loading branch information
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
class FormBlock extends Block | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $singular_name = 'Form Block'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $plural_name = 'Form Blocks'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $db = array( | ||
'Content' => 'HTMLText', | ||
); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $has_one = array( | ||
'Form' => 'UserDefinedForm', | ||
); | ||
|
||
/** | ||
* @return FieldList | ||
*/ | ||
public function getCMSFields() | ||
{ | ||
$fields = singleton('Block')->getCMSFields(); | ||
|
||
if (class_exists('UserDefinedForm')) { | ||
$fields->addFieldToTab('Root.Main', DropdownField::create( | ||
'FormID', | ||
'Form', | ||
UserDefinedForm::get()->map() | ||
)->setEmptyString('')); | ||
} | ||
|
||
$fields->addFieldToTab('Root.Main', HtmlEditorField::create('Content')); | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* @return Forms|HTMLText | ||
*/ | ||
public function BlockForm() | ||
{ | ||
if ($this->Form()->exists()) { | ||
$controller = new UserDefinedForm_Controller($this->Form()); | ||
$current = Controller::curr(); | ||
if ($current && $current->getAction() == 'finished') { | ||
return $controller->renderWith('ReceivedFormSubmission'); | ||
} | ||
$form = $controller->Form(); | ||
return $form; | ||
} | ||
} | ||
|
||
/** | ||
* @param null $member | ||
* @return bool | ||
*/ | ||
public function canCreate($member = null) | ||
{ | ||
if (!class_exists('UserDefinedForm')) { | ||
return false; | ||
} | ||
return parent::canCreate(); | ||
} | ||
|
||
/** | ||
* @param null $member | ||
* @return bool | ||
*/ | ||
public function canView($member = null) | ||
{ | ||
if (!class_exists('UserDefinedForm')) { | ||
return false; | ||
} | ||
return parent::canView(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="$CSSClasses"> | ||
<h3>$Title</h3> | ||
<% if $Content %>$Content<% end_if %> | ||
$BlockForm | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class FormBlockTest extends SapphireTest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml'; | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetCMSFields() | ||
{ | ||
$object = $this->objFromFixture('FormBlock', 'one'); | ||
$fields = $object->getCMSFields(); | ||
$this->assertInstanceOf('FieldList', $fields); | ||
$this->assertNotNull($fields->dataFieldByName('FormID')); | ||
} | ||
} |