Magento – How to pass data to UiComponent Area

magento2registryuicomponent

I have try to use register to save value and call it in some place of UiComponent such as ButtonProvider or Field OptionSource but seem it doesn't work. Is that a right way to do it or i am doing wrong

In controller i save variable to register

$this->_coreRegistry->register('someVal',data);

In another place i get data by registry

$this->_coreRegistry->registry('someVal');

Best Answer

I found solution for my question. Use Persistor instead of registry. Some case you need to pass data to Component area such as : Form. You can use Persistor to get this data instead use registry. Registry usually use in Controllers or Models

use Magento\Framework\App\Request\DataPersistorInterface;

/**
 * @var DataPersistorInterface
 */
protected $dataPersistor;

public function __construct(
    DataPersistorInterface $dataPersistor
){
    $this->dataPersistor = $dataPersistor;
}

protected function saveDataToPersistor() {
 $this->dataPersistor->set('val', $value);
}     

To get data in persistor use get method

$this->dataPersistor->get('val');
Related Topic