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 🤩
8 Comments
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks! https://www.binance.info/join?ref=P9L9FQKY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.