0

I have created a simple crud module that renders form with a few basic fields and saves data into database. Module is working fine and saving data correctly in the database.

Issue is before rendering form value I want to add a prefix to URL, something like this.

public function getInstagramLink()
{
    return 'https:'.$this->getData('instagram_link');
}

I have added this method within Model but that doesn't seem to be working

namespace Vendor\Module\Model;

class Instalocator extends \Magento\Framework\Model\AbstractModel
{
    protected function _construct()
    {
        $this->_init(\Vendor\Module\Model\ResourceModel\Instalocator ::class);
    }

    public function getInstagramLink()
    {
        return 'https:'.$this->getData('instagram_link');
    }
}

This doesn't seem to be working. How to do this correctly to set/get value before/after saving into database?

3
  • Do you want to save the field in DB with the prefix or just want to show the prefix while rendering the form? Are you using block or UI component to render the field? Jan 21, 2021 at 4:53
  • well, actually I want to store URL as encoded in database and while fetching from database decode the URL. I don't know how to modify (get/set) value with custom logic before saving into database. Jan 21, 2021 at 5:15
  • 1
    For encoding, you'll have to do it in either beforeSave method of your model or simply Save.php file of your module, just before saving your model. and for decoding before admin form loading, you can decode it in either you model's afterLoad method or in DataProvider class. Jan 21, 2021 at 7:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.