From 583fa821fc7ef77d17aeec2e18080a1d59d3c74c Mon Sep 17 00:00:00 2001 From: innomedia Date: Mon, 13 Jan 2020 11:38:18 +0100 Subject: [PATCH] init --- _config.php | 0 _config/config.yml | 7 +++ composer.json | 16 ++++++ src/GDPRFormPageExtension.php | 27 ++++++++++ src/GDPRSiteConfigExtension.php | 40 ++++++++++++++ src/GPDREditableCheckbox.php | 70 +++++++++++++++++++++++++ templates/GDPRCheckboxField.ss | 31 +++++++++++ templates/GDPRFieldHolder.ss | 3 ++ templates/UserFormsHTMLCheckboxField.ss | 33 ++++++++++++ 9 files changed, 227 insertions(+) create mode 100755 _config.php create mode 100755 _config/config.yml create mode 100644 composer.json create mode 100755 src/GDPRFormPageExtension.php create mode 100755 src/GDPRSiteConfigExtension.php create mode 100755 src/GPDREditableCheckbox.php create mode 100755 templates/GDPRCheckboxField.ss create mode 100755 templates/GDPRFieldHolder.ss create mode 100755 templates/UserFormsHTMLCheckboxField.ss diff --git a/_config.php b/_config.php new file mode 100755 index 0000000..e69de29 diff --git a/_config/config.yml b/_config/config.yml new file mode 100755 index 0000000..e707952 --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,7 @@ +--- +Name: thermotex +--- + +SilverStripe\SiteConfig\SiteConfig: + extensions: + - GDPRSiteConfigExtension diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ced7edf --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name":"innomedia/GDPR", + "description": "Silverstripe 4 GDPR", + "authors": [ + { + "name":"Innomedia AG", + "email": "bk@innomedia.de" + } + ], + "autoload": { + "psr-4": { + "GDPR\\": "src/" + } + } + } + diff --git a/src/GDPRFormPageExtension.php b/src/GDPRFormPageExtension.php new file mode 100755 index 0000000..7b0da68 --- /dev/null +++ b/src/GDPRFormPageExtension.php @@ -0,0 +1,27 @@ +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"); + } + } +} diff --git a/src/GDPRSiteConfigExtension.php b/src/GDPRSiteConfigExtension.php new file mode 100755 index 0000000..7cc2378 --- /dev/null +++ b/src/GDPRSiteConfigExtension.php @@ -0,0 +1,40 @@ + '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; + } +} diff --git a/src/GPDREditableCheckbox.php b/src/GPDREditableCheckbox.php new file mode 100755 index 0000000..073fdf4 --- /dev/null +++ b/src/GPDREditableCheckbox.php @@ -0,0 +1,70 @@ + '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; + } +} diff --git a/templates/GDPRCheckboxField.ss b/templates/GDPRCheckboxField.ss new file mode 100755 index 0000000..8ce966b --- /dev/null +++ b/templates/GDPRCheckboxField.ss @@ -0,0 +1,31 @@ +
+ + +
+ \ No newline at end of file diff --git a/templates/GDPRFieldHolder.ss b/templates/GDPRFieldHolder.ss new file mode 100755 index 0000000..256de49 --- /dev/null +++ b/templates/GDPRFieldHolder.ss @@ -0,0 +1,3 @@ +
+ $Field +
\ No newline at end of file diff --git a/templates/UserFormsHTMLCheckboxField.ss b/templates/UserFormsHTMLCheckboxField.ss new file mode 100755 index 0000000..03b3194 --- /dev/null +++ b/templates/UserFormsHTMLCheckboxField.ss @@ -0,0 +1,33 @@ +
+ aria-describedby="{$Name}_right_title" <% end_if %>/> + +
+