Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
innomedia committed Jan 13, 2020
1 parent a784f99 commit 583fa82
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 0 deletions.
Empty file added _config.php
Empty file.
7 changes: 7 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: thermotex
---

SilverStripe\SiteConfig\SiteConfig:
extensions:
- GDPRSiteConfigExtension
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name":"innomedia/GDPR",
"description": "Silverstripe 4 GDPR",
"authors": [
{
"name":"Innomedia AG",
"email": "bk@innomedia.de"
}
],
"autoload": {
"psr-4": {
"GDPR\\": "src/"
}
}
}

27 changes: 27 additions & 0 deletions src/GDPRFormPageExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
use SilverStripe\Core\Extension;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\SiteConfig\SiteConfig;
class GDPRFormPageExtension extends Extension
{
// Add $this->extend('updateFormWithGDPRFields', $fields,$requirements);
// To Form after all Fields have been added
public function updateFormWithGDPRFields($fields,$requirements)
{
$siteconfig = SiteConfig::get()->first();
if($siteconfig->FormularDatenschutztext != "")
{
$fields->push($GDPRField = CheckboxField::create(
'DataProtection',
'DataProtection'
));
if($siteconfig->ExtraCSS != "")
{
$GDPRField->addExtraClass($siteconfig->ExtraCSS);
}
$GDPRField->setTemplate("GDPRCheckboxField");
$GDPRField->setFieldHolderTemplate("GDPRFieldHolder");
$requirements->addRequiredField("DataProtection");
}
}
}
40 changes: 40 additions & 0 deletions src/GDPRSiteConfigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextField;

class GDPRSiteConfigExtension extends DataExtension
{
/**
* Database fields
* @var array
*/
private static $db = array(
'FormularDatenschutztext' => 'HTMLText',
'ExtraCSS' =>'Text'
);
/**
* Update Fields
* @return FieldList
*/
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$fields->addFieldToTab(
'Root.FormularDatenschutz',
HtmlEditorField::create(
'FormularDatenschutztext',
'Formular Datenschutz Text'
)
);
$fields->addFieldToTab(
'Root.FormularDatenschutz',
TextField::create(
'ExtraCSS',
'CSS'
)
);
return $fields;
}
}
70 changes: 70 additions & 0 deletions src/GPDREditableCheckbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

use SilverStripe\Forms\CheckboxField;
use SilverStripe\UserForms\Model\EditableFormField;

if (!class_exists(EditableFormField::class)) {
return;
}
/**
* EditableCheckbox
*
* A user modifiable checkbox on a UserDefinedForm
*
* @package userforms
*/

class GPDREditableCheckbox extends EditableFormField
{
private static $singular_name = 'Datenschutz Feld';

private static $plural_name = 'Datenschutz Felder';

protected $jsEventHandler = 'click';

private static $db = [
'CheckedDefault' => 'Boolean' // from CustomSettings
];

private static $table_name = 'EditableDatenschutzCheckbox';

/**
* @return FieldList
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->replaceField('Default', CheckboxField::create(
"CheckedDefault",
_t('SilverStripe\\UserForms\\Model\\EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
));

return $fields;
}

public function getFormField()
{
$field = CheckboxField::create($this->Name, $this->Title ?: false, $this->CheckedDefault)
->setFieldHolderTemplate("GDPRFieldHolder")
->setTemplate("GDPRCheckboxField");

$this->doUpdateFormField($field);

return $field;
}

public function getValueFromData($data)
{
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false;

return ($value)
? _t('SilverStripe\\UserForms\\Model\\EditableFormField.YES', 'Yes')
: _t('SilverStripe\\UserForms\\Model\\EditableFormField.NO', 'No');
}

public function isCheckBoxField()
{
return true;
}
}
31 changes: 31 additions & 0 deletions templates/GDPRCheckboxField.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="contactGDPR">
<input $AttributesHTML />
<label>{$SiteConfig.FormularDatenschutztext}</label>
</div>
<style>
.contactGDPR
{
margin-top:20px;
}
.contactGDPR label
{
display:inline-block !important;
position: relative;
top:-3px;
width: calc(100% - 40px);
text-transform: none;
}
.contactGDPR label p:last-child
{
margin-bottom:0;
}
.contactGDPR input.checkbox
{
height:auto !important;
width:30px !important;
display:inline-block !important;
float:left;
position: relative;
top:-3px;
}
</style>
3 changes: 3 additions & 0 deletions templates/GDPRFieldHolder.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="$HolderID" class="field $SiteConfig.ExtraCSS">
$Field
</div>
33 changes: 33 additions & 0 deletions templates/UserFormsHTMLCheckboxField.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="contactGDPR">
<input $AttributesHTML<% if $RightTitle %>aria-describedby="{$Name}_right_title" <% end_if %>/>
<label>{$SiteConfig.FormularDatenschutztext}</label>
</div>
<style>
.contactGDPR
{
margin-top:20px;
}
.contactGDPR label
{
display:inline-block;
position: relative;
top:-3px;
width: calc(100% - 40px);
text-transform: none;
padding-left:30px !important;
}
.contactGDPR label p:last-child
{
margin-bottom:0;
}
.contactGDPR input.checkbox
{
height:auto !important;
width:30px !important;
display:inline-block !important;
margin-left:0;
float:left;
position:relative !important;
top:-3px;
}
</style>

0 comments on commit 583fa82

Please sign in to comment.