Additional Consent
GDPR module will automatically show all registered consents below form. All we need is to add a consent to the registered personal data form.
Here is an example on how to add additional consent to the “Contact Us” form.
-
Add
forms_load_after
event listener inetc/events.xml
file:<event name="swissup_gdpr_personal_data_forms_load_after"> <observer name="vendor_module_register_consents" instance="Vendor\Module\Observer\RegisterAdditionalConsents" /> </event>
-
Create
RegisterAdditionalConsents
observer that will add a consent:<?php namespace Vendor\Module\Observer; class RegisterAdditionalConsents implements \Magento\Framework\Event\ObserverInterface { /** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $observer->getCollection()->getItemById('magento:contact-us')->addConsent([ 'html_id' => 'vendor_module_id', 'sort_order' => 0, 'title' => __('Custom consent added via event observer'), 'enabled' => 1, ]); } }
-
Check the “Contact Us” page. Now it will have your consent too. You don’t need to add validators or other logic. GDPR module will do the rest for you.