In this blog, I created admin role save after event to save custom field data in table
create events.xml
file at app/code/<Vendor>/<Module>/etc/events.xml
XML
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="admin_permissions_role_prepare_save">
<observer name="magedad_module_observer_backend_admin_permissionsrolepreparesave_admin_permissions_role_prepare_save" instance="MageDad\Module\Observer\Backend\Admin\PermissionsRolePrepareSave"/>
</event>
</config>
Now Create observer PermissionsRolePrepareSave
for save field field_name
data in database.
Create file at path app/code/MageDad/Module/Observer/Backend/Admin/PermissionsRolePrepareSave.php
PHP
<?php
declare(strict_types=1);
namespace MageDad\Module\Observer\Backend\Admin;
class PermissionsRolePrepareSave implements \Magento\Framework\Event\ObserverInterface
{
/**
* Execute observer
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(
\Magento\Framework\Event\Observer $observer
) {
$role = $observer->getEvent()->getObject();
$request = $observer->getEvent()->getRequest();
$data = $request->getPostValue();
if (isset($data['field_name'])) {
$fieldName = $data['field_name'];
$role->setData('field_name' , $fieldName);
}
}
}
I hope this blog is useful for save role field data in database. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.
Keep liking 👍 Keep sharing 📣 Keep loving ❤️ Keep inspiring 🤩