Data population in UI form Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can i rewrite TierPrice Block in Magento2uiComponent Form. How to show data from DB tableHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?Magento 2: How to override newsletter Subscriber modelUnable to save column in flexible tables (grids) in the system configurationMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formHow is the array $data parameter set in Magento 2 (dataObject constructor)Form is not displayed on panel admin Magento 2Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?

Can I take recommendation from someone I met at a conference?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

Etymology of 見舞い

Can I ask an author to send me his ebook?

Determine the generator of an ideal of ring of integers

How to create a command for the "strange m" symbol in latex?

How do I deal with an erroneously large refund?

Compiling and throwing simple dynamic exceptions at runtime for JVM

What is the evidence that custom checks in Northern Ireland are going to result in violence?

Trying to enter the Fox's den

Are Flameskulls resistant to magical piercing damage?

Can this water damage be explained by lack of gutters and grading issues?

What's the connection between Mr. Nancy and fried chicken?

Why did Europeans not widely domesticate foxes?

Short story about an alien named Ushtu(?) coming from a future Earth, when ours was destroyed by a nuclear explosion

Are bags of holding fireproof?

Raising a bilingual kid. When should we introduce the majority language?

How do I overlay a PNG over two videos (one video overlays another) in one command using FFmpeg?

How to charge percentage of transaction cost?

Why not use the yoke to control yaw, as well as pitch and roll?

Unix AIX passing variable and arguments to expect and spawn

tabularx column has extra padding at right?

Who's this lady in the war room?



Data population in UI form



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How can i rewrite TierPrice Block in Magento2uiComponent Form. How to show data from DB tableHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?Magento 2: How to override newsletter Subscriber modelUnable to save column in flexible tables (grids) in the system configurationMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formHow is the array $data parameter set in Magento 2 (dataObject constructor)Form is not displayed on panel admin Magento 2Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6















Im trying to build a custom admin form (using ui components) for a custom entity. We can assume the entity is very simple(e.g. id,name)



One thing that i have hard time with, is populating the form with data.



For this purpose i wrote a custom data provider which looks something like this:



public function getData()

if (isset($this->loadedData))
return $this->loadedData;


$items = $this->collection->getItems();
/** @var Customer $customer */
foreach ($items as $faq)
$this->loadedData[$faq->getId()] = $faq->getData();


$data = $this->getSession()->getFormData();
if (!empty($data))
$faqId = isset($data) ? $data : null;
$this->loadedData[$faqId] = $data;
$this->getSession()->unsFormData();


return $this->loadedData;



So the actual data are right under the id of the entity.



The ui component has a single fieldset with one field:



<fieldset name="general">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Conditions</item>
</item>
</argument>
<field name="name">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Label</item>
<item name="formElement" xsi:type="string">input</item>
<item name="dataScope" xsi:type="string">name</item>
<item name="source" xsi:type="string">general</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
</fieldset>


The problem is, that the field never gets populated. Only way at the moment is to change stracture of the array returned by data provider:



$this->loadedData[$faq->getId()]['general'] = $faq->getData();


So the structure of the array has the same structure as fieldset -> field in the xml.



This seems to make some sense, however when i look how CMS module is defined for pages and blocks, it doesn't use the fieldset -> field hierarchy.



The data providers don't contain the fieldset key anywhere(or at least not from the getData) method, but the xml uses magical source 'block'.



For example for block



MagentoCmsModelBlockDataProvider

public function getData()

if (isset($this->loadedData))
return $this->loadedData;

$items = $this->collection->getItems();
/** @var MagentoCmsModelBlock $block */
foreach ($items as $block)
$this->loadedData[$block->getId()] = $block->getData();


$data = $this->dataPersistor->get('cms_block');
if (!empty($data))
$block = $this->collection->getNewEmptyItem();
$block->setData($data);
$this->loadedData[$block->getId()] = $block->getData();
$this->dataPersistor->clear('cms_block');


return $this->loadedData;


MagentoCmsviewui_componentcms_block_form.xml

<fieldset name="general">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string"/>
</item>
</argument>
<field name="is_active">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">boolean</item>
<item name="label" xsi:type="string" translate="true">Enable Block</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="source" xsi:type="string">block</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">is_active</item>
<item name="prefer" xsi:type="string">toggle</item>
<item name="valueMap" xsi:type="array">
<item name="true" xsi:type="number">1</item>
<item name="false" xsi:type="number">0</item>
</item>
<item name="default" xsi:type="number">1</item>
</item>
</argument>
</field>


Where/How is this 'block' source created?



Do i really need to have the fieldset keys in data returned from the data provider?



Any help would be greatly appreciated.










share|improve this question














bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    6















    Im trying to build a custom admin form (using ui components) for a custom entity. We can assume the entity is very simple(e.g. id,name)



    One thing that i have hard time with, is populating the form with data.



    For this purpose i wrote a custom data provider which looks something like this:



    public function getData()

    if (isset($this->loadedData))
    return $this->loadedData;


    $items = $this->collection->getItems();
    /** @var Customer $customer */
    foreach ($items as $faq)
    $this->loadedData[$faq->getId()] = $faq->getData();


    $data = $this->getSession()->getFormData();
    if (!empty($data))
    $faqId = isset($data) ? $data : null;
    $this->loadedData[$faqId] = $data;
    $this->getSession()->unsFormData();


    return $this->loadedData;



    So the actual data are right under the id of the entity.



    The ui component has a single fieldset with one field:



    <fieldset name="general">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">Conditions</item>
    </item>
    </argument>
    <field name="name">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="dataType" xsi:type="string">text</item>
    <item name="label" xsi:type="string" translate="true">Label</item>
    <item name="formElement" xsi:type="string">input</item>
    <item name="dataScope" xsi:type="string">name</item>
    <item name="source" xsi:type="string">general</item>
    <item name="validation" xsi:type="array">
    <item name="required-entry" xsi:type="boolean">true</item>
    </item>
    </item>
    </argument>
    </field>
    </fieldset>


    The problem is, that the field never gets populated. Only way at the moment is to change stracture of the array returned by data provider:



    $this->loadedData[$faq->getId()]['general'] = $faq->getData();


    So the structure of the array has the same structure as fieldset -> field in the xml.



    This seems to make some sense, however when i look how CMS module is defined for pages and blocks, it doesn't use the fieldset -> field hierarchy.



    The data providers don't contain the fieldset key anywhere(or at least not from the getData) method, but the xml uses magical source 'block'.



    For example for block



    MagentoCmsModelBlockDataProvider

    public function getData()

    if (isset($this->loadedData))
    return $this->loadedData;

    $items = $this->collection->getItems();
    /** @var MagentoCmsModelBlock $block */
    foreach ($items as $block)
    $this->loadedData[$block->getId()] = $block->getData();


    $data = $this->dataPersistor->get('cms_block');
    if (!empty($data))
    $block = $this->collection->getNewEmptyItem();
    $block->setData($data);
    $this->loadedData[$block->getId()] = $block->getData();
    $this->dataPersistor->clear('cms_block');


    return $this->loadedData;


    MagentoCmsviewui_componentcms_block_form.xml

    <fieldset name="general">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string"/>
    </item>
    </argument>
    <field name="is_active">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="dataType" xsi:type="string">boolean</item>
    <item name="label" xsi:type="string" translate="true">Enable Block</item>
    <item name="formElement" xsi:type="string">checkbox</item>
    <item name="source" xsi:type="string">block</item>
    <item name="sortOrder" xsi:type="number">10</item>
    <item name="dataScope" xsi:type="string">is_active</item>
    <item name="prefer" xsi:type="string">toggle</item>
    <item name="valueMap" xsi:type="array">
    <item name="true" xsi:type="number">1</item>
    <item name="false" xsi:type="number">0</item>
    </item>
    <item name="default" xsi:type="number">1</item>
    </item>
    </argument>
    </field>


    Where/How is this 'block' source created?



    Do i really need to have the fieldset keys in data returned from the data provider?



    Any help would be greatly appreciated.










    share|improve this question














    bumped to the homepage by Community 3 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      6












      6








      6


      1






      Im trying to build a custom admin form (using ui components) for a custom entity. We can assume the entity is very simple(e.g. id,name)



      One thing that i have hard time with, is populating the form with data.



      For this purpose i wrote a custom data provider which looks something like this:



      public function getData()

      if (isset($this->loadedData))
      return $this->loadedData;


      $items = $this->collection->getItems();
      /** @var Customer $customer */
      foreach ($items as $faq)
      $this->loadedData[$faq->getId()] = $faq->getData();


      $data = $this->getSession()->getFormData();
      if (!empty($data))
      $faqId = isset($data) ? $data : null;
      $this->loadedData[$faqId] = $data;
      $this->getSession()->unsFormData();


      return $this->loadedData;



      So the actual data are right under the id of the entity.



      The ui component has a single fieldset with one field:



      <fieldset name="general">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Conditions</item>
      </item>
      </argument>
      <field name="name">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="dataType" xsi:type="string">text</item>
      <item name="label" xsi:type="string" translate="true">Label</item>
      <item name="formElement" xsi:type="string">input</item>
      <item name="dataScope" xsi:type="string">name</item>
      <item name="source" xsi:type="string">general</item>
      <item name="validation" xsi:type="array">
      <item name="required-entry" xsi:type="boolean">true</item>
      </item>
      </item>
      </argument>
      </field>
      </fieldset>


      The problem is, that the field never gets populated. Only way at the moment is to change stracture of the array returned by data provider:



      $this->loadedData[$faq->getId()]['general'] = $faq->getData();


      So the structure of the array has the same structure as fieldset -> field in the xml.



      This seems to make some sense, however when i look how CMS module is defined for pages and blocks, it doesn't use the fieldset -> field hierarchy.



      The data providers don't contain the fieldset key anywhere(or at least not from the getData) method, but the xml uses magical source 'block'.



      For example for block



      MagentoCmsModelBlockDataProvider

      public function getData()

      if (isset($this->loadedData))
      return $this->loadedData;

      $items = $this->collection->getItems();
      /** @var MagentoCmsModelBlock $block */
      foreach ($items as $block)
      $this->loadedData[$block->getId()] = $block->getData();


      $data = $this->dataPersistor->get('cms_block');
      if (!empty($data))
      $block = $this->collection->getNewEmptyItem();
      $block->setData($data);
      $this->loadedData[$block->getId()] = $block->getData();
      $this->dataPersistor->clear('cms_block');


      return $this->loadedData;


      MagentoCmsviewui_componentcms_block_form.xml

      <fieldset name="general">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string"/>
      </item>
      </argument>
      <field name="is_active">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="dataType" xsi:type="string">boolean</item>
      <item name="label" xsi:type="string" translate="true">Enable Block</item>
      <item name="formElement" xsi:type="string">checkbox</item>
      <item name="source" xsi:type="string">block</item>
      <item name="sortOrder" xsi:type="number">10</item>
      <item name="dataScope" xsi:type="string">is_active</item>
      <item name="prefer" xsi:type="string">toggle</item>
      <item name="valueMap" xsi:type="array">
      <item name="true" xsi:type="number">1</item>
      <item name="false" xsi:type="number">0</item>
      </item>
      <item name="default" xsi:type="number">1</item>
      </item>
      </argument>
      </field>


      Where/How is this 'block' source created?



      Do i really need to have the fieldset keys in data returned from the data provider?



      Any help would be greatly appreciated.










      share|improve this question














      Im trying to build a custom admin form (using ui components) for a custom entity. We can assume the entity is very simple(e.g. id,name)



      One thing that i have hard time with, is populating the form with data.



      For this purpose i wrote a custom data provider which looks something like this:



      public function getData()

      if (isset($this->loadedData))
      return $this->loadedData;


      $items = $this->collection->getItems();
      /** @var Customer $customer */
      foreach ($items as $faq)
      $this->loadedData[$faq->getId()] = $faq->getData();


      $data = $this->getSession()->getFormData();
      if (!empty($data))
      $faqId = isset($data) ? $data : null;
      $this->loadedData[$faqId] = $data;
      $this->getSession()->unsFormData();


      return $this->loadedData;



      So the actual data are right under the id of the entity.



      The ui component has a single fieldset with one field:



      <fieldset name="general">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Conditions</item>
      </item>
      </argument>
      <field name="name">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="dataType" xsi:type="string">text</item>
      <item name="label" xsi:type="string" translate="true">Label</item>
      <item name="formElement" xsi:type="string">input</item>
      <item name="dataScope" xsi:type="string">name</item>
      <item name="source" xsi:type="string">general</item>
      <item name="validation" xsi:type="array">
      <item name="required-entry" xsi:type="boolean">true</item>
      </item>
      </item>
      </argument>
      </field>
      </fieldset>


      The problem is, that the field never gets populated. Only way at the moment is to change stracture of the array returned by data provider:



      $this->loadedData[$faq->getId()]['general'] = $faq->getData();


      So the structure of the array has the same structure as fieldset -> field in the xml.



      This seems to make some sense, however when i look how CMS module is defined for pages and blocks, it doesn't use the fieldset -> field hierarchy.



      The data providers don't contain the fieldset key anywhere(or at least not from the getData) method, but the xml uses magical source 'block'.



      For example for block



      MagentoCmsModelBlockDataProvider

      public function getData()

      if (isset($this->loadedData))
      return $this->loadedData;

      $items = $this->collection->getItems();
      /** @var MagentoCmsModelBlock $block */
      foreach ($items as $block)
      $this->loadedData[$block->getId()] = $block->getData();


      $data = $this->dataPersistor->get('cms_block');
      if (!empty($data))
      $block = $this->collection->getNewEmptyItem();
      $block->setData($data);
      $this->loadedData[$block->getId()] = $block->getData();
      $this->dataPersistor->clear('cms_block');


      return $this->loadedData;


      MagentoCmsviewui_componentcms_block_form.xml

      <fieldset name="general">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string"/>
      </item>
      </argument>
      <field name="is_active">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="dataType" xsi:type="string">boolean</item>
      <item name="label" xsi:type="string" translate="true">Enable Block</item>
      <item name="formElement" xsi:type="string">checkbox</item>
      <item name="source" xsi:type="string">block</item>
      <item name="sortOrder" xsi:type="number">10</item>
      <item name="dataScope" xsi:type="string">is_active</item>
      <item name="prefer" xsi:type="string">toggle</item>
      <item name="valueMap" xsi:type="array">
      <item name="true" xsi:type="number">1</item>
      <item name="false" xsi:type="number">0</item>
      </item>
      <item name="default" xsi:type="number">1</item>
      </item>
      </argument>
      </field>


      Where/How is this 'block' source created?



      Do i really need to have the fieldset keys in data returned from the data provider?



      Any help would be greatly appreciated.







      magento2 magento-2.1 adminform uicomponent






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 '16 at 19:01









      LangleyLangley

      609320




      609320





      bumped to the homepage by Community 3 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 3 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          2 Answers
          2






          active

          oldest

          votes


















          0














          If you see the the customer edit form and get a look over the array returned by getdata() method . It sends out a array as [id][fieldset_name][data]. So here the key is mentioned during edit action.I guess this is the standard way of loading a UI form with data during edit.






          share|improve this answer























          • Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

            – Langley
            Aug 24 '16 at 5:51












          • @Langley did you find out much more about this? In the same predicament now. Thanks

            – Tom Burman
            Mar 9 '17 at 12:49











          • Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

            – Langley
            Mar 9 '17 at 16:55












          • Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

            – Aditya Yadav
            Jun 25 '18 at 8:03


















          0














          Using dataPersistor to get Form data, thought you're using getSession



          $data = $this->getSession()->getFormData();


          Save action



          <?php


          namespace VendorModuleControllerAdminhtmlScheduler;

          use MagentoFrameworkExceptionLocalizedException;

          class Save extends MagentoBackendAppAction


          protected $dataPersistor;

          /**
          * @param MagentoBackendAppActionContext $context
          * @param MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          */
          public function __construct(
          MagentoBackendAppActionContext $context,
          MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          )
          $this->dataPersistor = $dataPersistor;
          parent::__construct($context);


          /**
          * Save action
          *
          * @return MagentoFrameworkControllerResultInterface
          */
          public function execute()

          /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
          $resultRedirect = $this->resultRedirectFactory->create();
          $data = $this->getRequest()->getPostValue();
          if ($data)
          $id = $this->getRequest()->getParam('scheduler_id');

          $model = $this->_objectManager->create('VendorModuleModelScheduler')->load($id);
          if (!$model->getId() && $id)
          $this->messageManager->addErrorMessage(__('This Scheduler no longer exists.'));
          return $resultRedirect->setPath('*/*/');


          $model->setData($data);

          try

          $model->save();
          $this->messageManager->addSuccessMessage(__('You saved the Scheduler.'));
          $this->dataPersistor->clear('engraving_scheduler');

          if ($this->getRequest()->getParam('back'))
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $model->getId()]);

          return $resultRedirect->setPath('*/*/');
          catch (LocalizedException $e)
          $this->messageManager->addErrorMessage($e->getMessage());
          catch (Exception $e)
          $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Scheduler.'));


          $this->dataPersistor->set('engraving_scheduler', $data);
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $this->getRequest()->getParam('scheduler_id')]);

          return $resultRedirect->setPath('*/*/');




          DataProvider



          <?php


          namespace VendorModuleModelScheduler;

          use VendorModuleModelResourceModelSchedulerCollectionFactory;
          use MagentoFrameworkAppRequestDataPersistorInterface;

          class DataProvider extends MagentoUiDataProviderAbstractDataProvider


          protected $dataPersistor;

          protected $loadedData;
          protected $collection;


          /**
          * Constructor
          *
          * @param string $name
          * @param string $primaryFieldName
          * @param string $requestFieldName
          * @param CollectionFactory $collectionFactory
          * @param DataPersistorInterface $dataPersistor
          * @param array $meta
          * @param array $data
          */
          public function __construct(
          $name,
          $primaryFieldName,
          $requestFieldName,
          CollectionFactory $collectionFactory,
          DataPersistorInterface $dataPersistor,
          array $meta = [],
          array $data = []
          )
          $this->collection = $collectionFactory->create();
          $this->dataPersistor = $dataPersistor;
          parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);


          /**
          * Get data
          *
          * @return array
          */
          public function getData()

          if (isset($this->loadedData))
          return $this->loadedData;

          $items = $this->collection->getItems();
          foreach ($items as $model)
          $this->loadedData[$model->getId()] = $model->getData();

          $data = $this->dataPersistor->get('engraving_scheduler');

          if (!empty($data))
          $model = $this->collection->getNewEmptyItem();
          $model->setData($data);
          $this->loadedData[$model->getId()] = $model->getData();
          $this->dataPersistor->clear('engraving_scheduler');


          return $this->loadedData;




          ui form xml



           <?xml version="1.0" ?>
          <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="provider" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          <item name="deps" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          </item>
          <item name="label" translate="true" xsi:type="string">General Information</item>
          <item name="config" xsi:type="array">
          <item name="dataScope" xsi:type="string">data</item>
          <item name="namespace" xsi:type="string">engraving_scheduler_form</item>
          </item>
          <item name="template" xsi:type="string">templates/form/collapsible</item>
          <item name="buttons" xsi:type="array">
          <item name="back" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditBackButton</item>
          <item name="delete" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditDeleteButton</item>
          <item name="save" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveButton</item>
          <item name="save_and_continue" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveAndContinueButton</item>
          </item>
          </argument>
          <dataSource name="scheduler_form_data_source">
          <argument name="dataProvider" xsi:type="configurableObject">
          <argument name="class" xsi:type="string">VendorModuleModelSchedulerDataProvider</argument>
          <argument name="name" xsi:type="string">scheduler_form_data_source</argument>
          <argument name="primaryFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="requestFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="submit_url" path="*/*/save" xsi:type="url"/>
          </item>
          </argument>
          </argument>
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
          </item>
          </argument>
          </dataSource>
          <fieldset name="General">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="label" xsi:type="string"/>
          </item>
          </argument>
          <field name="label">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="dataType" xsi:type="string">text</item>
          <item name="label" translate="true" xsi:type="string">Title</item>
          <item name="formElement" xsi:type="string">input</item>
          <item name="source" xsi:type="string">Scheduler</item>
          <item name="sortOrder" xsi:type="number">10</item>
          <item name="dataScope" xsi:type="string">label</item>
          <item name="validation" xsi:type="array">
          <item name="required-entry" xsi:type="boolean">true</item>
          </item>
          </item>
          </argument>
          </field>
          </fieldset>
          </form>





          share|improve this answer























          • Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

            – Langley
            Nov 15 '18 at 8:04











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f132707%2fdata-population-in-ui-form%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you see the the customer edit form and get a look over the array returned by getdata() method . It sends out a array as [id][fieldset_name][data]. So here the key is mentioned during edit action.I guess this is the standard way of loading a UI form with data during edit.






          share|improve this answer























          • Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

            – Langley
            Aug 24 '16 at 5:51












          • @Langley did you find out much more about this? In the same predicament now. Thanks

            – Tom Burman
            Mar 9 '17 at 12:49











          • Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

            – Langley
            Mar 9 '17 at 16:55












          • Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

            – Aditya Yadav
            Jun 25 '18 at 8:03















          0














          If you see the the customer edit form and get a look over the array returned by getdata() method . It sends out a array as [id][fieldset_name][data]. So here the key is mentioned during edit action.I guess this is the standard way of loading a UI form with data during edit.






          share|improve this answer























          • Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

            – Langley
            Aug 24 '16 at 5:51












          • @Langley did you find out much more about this? In the same predicament now. Thanks

            – Tom Burman
            Mar 9 '17 at 12:49











          • Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

            – Langley
            Mar 9 '17 at 16:55












          • Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

            – Aditya Yadav
            Jun 25 '18 at 8:03













          0












          0








          0







          If you see the the customer edit form and get a look over the array returned by getdata() method . It sends out a array as [id][fieldset_name][data]. So here the key is mentioned during edit action.I guess this is the standard way of loading a UI form with data during edit.






          share|improve this answer













          If you see the the customer edit form and get a look over the array returned by getdata() method . It sends out a array as [id][fieldset_name][data]. So here the key is mentioned during edit action.I guess this is the standard way of loading a UI form with data during edit.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 24 '16 at 5:13









          Aditya YadavAditya Yadav

          514




          514












          • Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

            – Langley
            Aug 24 '16 at 5:51












          • @Langley did you find out much more about this? In the same predicament now. Thanks

            – Tom Burman
            Mar 9 '17 at 12:49











          • Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

            – Langley
            Mar 9 '17 at 16:55












          • Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

            – Aditya Yadav
            Jun 25 '18 at 8:03

















          • Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

            – Langley
            Aug 24 '16 at 5:51












          • @Langley did you find out much more about this? In the same predicament now. Thanks

            – Tom Burman
            Mar 9 '17 at 12:49











          • Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

            – Langley
            Mar 9 '17 at 16:55












          • Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

            – Aditya Yadav
            Jun 25 '18 at 8:03
















          Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

          – Langley
          Aug 24 '16 at 5:51






          Yes some of the forms use this and in case of tabbed form like customer it makes sense. However for very simple form this is way too complicated. The question I really have is, how the cms module doest this? Because the fieldset name is not used there.

          – Langley
          Aug 24 '16 at 5:51














          @Langley did you find out much more about this? In the same predicament now. Thanks

          – Tom Burman
          Mar 9 '17 at 12:49





          @Langley did you find out much more about this? In the same predicament now. Thanks

          – Tom Burman
          Mar 9 '17 at 12:49













          Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

          – Langley
          Mar 9 '17 at 16:55






          Not that much, but ended up making it work somehow. Cant remember. Looking into the original question i think it may be wrong dataScope in the form configuration (not the fields)

          – Langley
          Mar 9 '17 at 16:55














          Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

          – Aditya Yadav
          Jun 25 '18 at 8:03





          Each form does contain a fieldset so format of [id][fieldset_name][data] if definitely correct.

          – Aditya Yadav
          Jun 25 '18 at 8:03













          0














          Using dataPersistor to get Form data, thought you're using getSession



          $data = $this->getSession()->getFormData();


          Save action



          <?php


          namespace VendorModuleControllerAdminhtmlScheduler;

          use MagentoFrameworkExceptionLocalizedException;

          class Save extends MagentoBackendAppAction


          protected $dataPersistor;

          /**
          * @param MagentoBackendAppActionContext $context
          * @param MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          */
          public function __construct(
          MagentoBackendAppActionContext $context,
          MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          )
          $this->dataPersistor = $dataPersistor;
          parent::__construct($context);


          /**
          * Save action
          *
          * @return MagentoFrameworkControllerResultInterface
          */
          public function execute()

          /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
          $resultRedirect = $this->resultRedirectFactory->create();
          $data = $this->getRequest()->getPostValue();
          if ($data)
          $id = $this->getRequest()->getParam('scheduler_id');

          $model = $this->_objectManager->create('VendorModuleModelScheduler')->load($id);
          if (!$model->getId() && $id)
          $this->messageManager->addErrorMessage(__('This Scheduler no longer exists.'));
          return $resultRedirect->setPath('*/*/');


          $model->setData($data);

          try

          $model->save();
          $this->messageManager->addSuccessMessage(__('You saved the Scheduler.'));
          $this->dataPersistor->clear('engraving_scheduler');

          if ($this->getRequest()->getParam('back'))
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $model->getId()]);

          return $resultRedirect->setPath('*/*/');
          catch (LocalizedException $e)
          $this->messageManager->addErrorMessage($e->getMessage());
          catch (Exception $e)
          $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Scheduler.'));


          $this->dataPersistor->set('engraving_scheduler', $data);
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $this->getRequest()->getParam('scheduler_id')]);

          return $resultRedirect->setPath('*/*/');




          DataProvider



          <?php


          namespace VendorModuleModelScheduler;

          use VendorModuleModelResourceModelSchedulerCollectionFactory;
          use MagentoFrameworkAppRequestDataPersistorInterface;

          class DataProvider extends MagentoUiDataProviderAbstractDataProvider


          protected $dataPersistor;

          protected $loadedData;
          protected $collection;


          /**
          * Constructor
          *
          * @param string $name
          * @param string $primaryFieldName
          * @param string $requestFieldName
          * @param CollectionFactory $collectionFactory
          * @param DataPersistorInterface $dataPersistor
          * @param array $meta
          * @param array $data
          */
          public function __construct(
          $name,
          $primaryFieldName,
          $requestFieldName,
          CollectionFactory $collectionFactory,
          DataPersistorInterface $dataPersistor,
          array $meta = [],
          array $data = []
          )
          $this->collection = $collectionFactory->create();
          $this->dataPersistor = $dataPersistor;
          parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);


          /**
          * Get data
          *
          * @return array
          */
          public function getData()

          if (isset($this->loadedData))
          return $this->loadedData;

          $items = $this->collection->getItems();
          foreach ($items as $model)
          $this->loadedData[$model->getId()] = $model->getData();

          $data = $this->dataPersistor->get('engraving_scheduler');

          if (!empty($data))
          $model = $this->collection->getNewEmptyItem();
          $model->setData($data);
          $this->loadedData[$model->getId()] = $model->getData();
          $this->dataPersistor->clear('engraving_scheduler');


          return $this->loadedData;




          ui form xml



           <?xml version="1.0" ?>
          <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="provider" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          <item name="deps" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          </item>
          <item name="label" translate="true" xsi:type="string">General Information</item>
          <item name="config" xsi:type="array">
          <item name="dataScope" xsi:type="string">data</item>
          <item name="namespace" xsi:type="string">engraving_scheduler_form</item>
          </item>
          <item name="template" xsi:type="string">templates/form/collapsible</item>
          <item name="buttons" xsi:type="array">
          <item name="back" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditBackButton</item>
          <item name="delete" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditDeleteButton</item>
          <item name="save" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveButton</item>
          <item name="save_and_continue" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveAndContinueButton</item>
          </item>
          </argument>
          <dataSource name="scheduler_form_data_source">
          <argument name="dataProvider" xsi:type="configurableObject">
          <argument name="class" xsi:type="string">VendorModuleModelSchedulerDataProvider</argument>
          <argument name="name" xsi:type="string">scheduler_form_data_source</argument>
          <argument name="primaryFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="requestFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="submit_url" path="*/*/save" xsi:type="url"/>
          </item>
          </argument>
          </argument>
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
          </item>
          </argument>
          </dataSource>
          <fieldset name="General">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="label" xsi:type="string"/>
          </item>
          </argument>
          <field name="label">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="dataType" xsi:type="string">text</item>
          <item name="label" translate="true" xsi:type="string">Title</item>
          <item name="formElement" xsi:type="string">input</item>
          <item name="source" xsi:type="string">Scheduler</item>
          <item name="sortOrder" xsi:type="number">10</item>
          <item name="dataScope" xsi:type="string">label</item>
          <item name="validation" xsi:type="array">
          <item name="required-entry" xsi:type="boolean">true</item>
          </item>
          </item>
          </argument>
          </field>
          </fieldset>
          </form>





          share|improve this answer























          • Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

            – Langley
            Nov 15 '18 at 8:04















          0














          Using dataPersistor to get Form data, thought you're using getSession



          $data = $this->getSession()->getFormData();


          Save action



          <?php


          namespace VendorModuleControllerAdminhtmlScheduler;

          use MagentoFrameworkExceptionLocalizedException;

          class Save extends MagentoBackendAppAction


          protected $dataPersistor;

          /**
          * @param MagentoBackendAppActionContext $context
          * @param MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          */
          public function __construct(
          MagentoBackendAppActionContext $context,
          MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          )
          $this->dataPersistor = $dataPersistor;
          parent::__construct($context);


          /**
          * Save action
          *
          * @return MagentoFrameworkControllerResultInterface
          */
          public function execute()

          /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
          $resultRedirect = $this->resultRedirectFactory->create();
          $data = $this->getRequest()->getPostValue();
          if ($data)
          $id = $this->getRequest()->getParam('scheduler_id');

          $model = $this->_objectManager->create('VendorModuleModelScheduler')->load($id);
          if (!$model->getId() && $id)
          $this->messageManager->addErrorMessage(__('This Scheduler no longer exists.'));
          return $resultRedirect->setPath('*/*/');


          $model->setData($data);

          try

          $model->save();
          $this->messageManager->addSuccessMessage(__('You saved the Scheduler.'));
          $this->dataPersistor->clear('engraving_scheduler');

          if ($this->getRequest()->getParam('back'))
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $model->getId()]);

          return $resultRedirect->setPath('*/*/');
          catch (LocalizedException $e)
          $this->messageManager->addErrorMessage($e->getMessage());
          catch (Exception $e)
          $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Scheduler.'));


          $this->dataPersistor->set('engraving_scheduler', $data);
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $this->getRequest()->getParam('scheduler_id')]);

          return $resultRedirect->setPath('*/*/');




          DataProvider



          <?php


          namespace VendorModuleModelScheduler;

          use VendorModuleModelResourceModelSchedulerCollectionFactory;
          use MagentoFrameworkAppRequestDataPersistorInterface;

          class DataProvider extends MagentoUiDataProviderAbstractDataProvider


          protected $dataPersistor;

          protected $loadedData;
          protected $collection;


          /**
          * Constructor
          *
          * @param string $name
          * @param string $primaryFieldName
          * @param string $requestFieldName
          * @param CollectionFactory $collectionFactory
          * @param DataPersistorInterface $dataPersistor
          * @param array $meta
          * @param array $data
          */
          public function __construct(
          $name,
          $primaryFieldName,
          $requestFieldName,
          CollectionFactory $collectionFactory,
          DataPersistorInterface $dataPersistor,
          array $meta = [],
          array $data = []
          )
          $this->collection = $collectionFactory->create();
          $this->dataPersistor = $dataPersistor;
          parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);


          /**
          * Get data
          *
          * @return array
          */
          public function getData()

          if (isset($this->loadedData))
          return $this->loadedData;

          $items = $this->collection->getItems();
          foreach ($items as $model)
          $this->loadedData[$model->getId()] = $model->getData();

          $data = $this->dataPersistor->get('engraving_scheduler');

          if (!empty($data))
          $model = $this->collection->getNewEmptyItem();
          $model->setData($data);
          $this->loadedData[$model->getId()] = $model->getData();
          $this->dataPersistor->clear('engraving_scheduler');


          return $this->loadedData;




          ui form xml



           <?xml version="1.0" ?>
          <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="provider" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          <item name="deps" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          </item>
          <item name="label" translate="true" xsi:type="string">General Information</item>
          <item name="config" xsi:type="array">
          <item name="dataScope" xsi:type="string">data</item>
          <item name="namespace" xsi:type="string">engraving_scheduler_form</item>
          </item>
          <item name="template" xsi:type="string">templates/form/collapsible</item>
          <item name="buttons" xsi:type="array">
          <item name="back" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditBackButton</item>
          <item name="delete" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditDeleteButton</item>
          <item name="save" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveButton</item>
          <item name="save_and_continue" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveAndContinueButton</item>
          </item>
          </argument>
          <dataSource name="scheduler_form_data_source">
          <argument name="dataProvider" xsi:type="configurableObject">
          <argument name="class" xsi:type="string">VendorModuleModelSchedulerDataProvider</argument>
          <argument name="name" xsi:type="string">scheduler_form_data_source</argument>
          <argument name="primaryFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="requestFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="submit_url" path="*/*/save" xsi:type="url"/>
          </item>
          </argument>
          </argument>
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
          </item>
          </argument>
          </dataSource>
          <fieldset name="General">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="label" xsi:type="string"/>
          </item>
          </argument>
          <field name="label">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="dataType" xsi:type="string">text</item>
          <item name="label" translate="true" xsi:type="string">Title</item>
          <item name="formElement" xsi:type="string">input</item>
          <item name="source" xsi:type="string">Scheduler</item>
          <item name="sortOrder" xsi:type="number">10</item>
          <item name="dataScope" xsi:type="string">label</item>
          <item name="validation" xsi:type="array">
          <item name="required-entry" xsi:type="boolean">true</item>
          </item>
          </item>
          </argument>
          </field>
          </fieldset>
          </form>





          share|improve this answer























          • Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

            – Langley
            Nov 15 '18 at 8:04













          0












          0








          0







          Using dataPersistor to get Form data, thought you're using getSession



          $data = $this->getSession()->getFormData();


          Save action



          <?php


          namespace VendorModuleControllerAdminhtmlScheduler;

          use MagentoFrameworkExceptionLocalizedException;

          class Save extends MagentoBackendAppAction


          protected $dataPersistor;

          /**
          * @param MagentoBackendAppActionContext $context
          * @param MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          */
          public function __construct(
          MagentoBackendAppActionContext $context,
          MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          )
          $this->dataPersistor = $dataPersistor;
          parent::__construct($context);


          /**
          * Save action
          *
          * @return MagentoFrameworkControllerResultInterface
          */
          public function execute()

          /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
          $resultRedirect = $this->resultRedirectFactory->create();
          $data = $this->getRequest()->getPostValue();
          if ($data)
          $id = $this->getRequest()->getParam('scheduler_id');

          $model = $this->_objectManager->create('VendorModuleModelScheduler')->load($id);
          if (!$model->getId() && $id)
          $this->messageManager->addErrorMessage(__('This Scheduler no longer exists.'));
          return $resultRedirect->setPath('*/*/');


          $model->setData($data);

          try

          $model->save();
          $this->messageManager->addSuccessMessage(__('You saved the Scheduler.'));
          $this->dataPersistor->clear('engraving_scheduler');

          if ($this->getRequest()->getParam('back'))
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $model->getId()]);

          return $resultRedirect->setPath('*/*/');
          catch (LocalizedException $e)
          $this->messageManager->addErrorMessage($e->getMessage());
          catch (Exception $e)
          $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Scheduler.'));


          $this->dataPersistor->set('engraving_scheduler', $data);
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $this->getRequest()->getParam('scheduler_id')]);

          return $resultRedirect->setPath('*/*/');




          DataProvider



          <?php


          namespace VendorModuleModelScheduler;

          use VendorModuleModelResourceModelSchedulerCollectionFactory;
          use MagentoFrameworkAppRequestDataPersistorInterface;

          class DataProvider extends MagentoUiDataProviderAbstractDataProvider


          protected $dataPersistor;

          protected $loadedData;
          protected $collection;


          /**
          * Constructor
          *
          * @param string $name
          * @param string $primaryFieldName
          * @param string $requestFieldName
          * @param CollectionFactory $collectionFactory
          * @param DataPersistorInterface $dataPersistor
          * @param array $meta
          * @param array $data
          */
          public function __construct(
          $name,
          $primaryFieldName,
          $requestFieldName,
          CollectionFactory $collectionFactory,
          DataPersistorInterface $dataPersistor,
          array $meta = [],
          array $data = []
          )
          $this->collection = $collectionFactory->create();
          $this->dataPersistor = $dataPersistor;
          parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);


          /**
          * Get data
          *
          * @return array
          */
          public function getData()

          if (isset($this->loadedData))
          return $this->loadedData;

          $items = $this->collection->getItems();
          foreach ($items as $model)
          $this->loadedData[$model->getId()] = $model->getData();

          $data = $this->dataPersistor->get('engraving_scheduler');

          if (!empty($data))
          $model = $this->collection->getNewEmptyItem();
          $model->setData($data);
          $this->loadedData[$model->getId()] = $model->getData();
          $this->dataPersistor->clear('engraving_scheduler');


          return $this->loadedData;




          ui form xml



           <?xml version="1.0" ?>
          <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="provider" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          <item name="deps" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          </item>
          <item name="label" translate="true" xsi:type="string">General Information</item>
          <item name="config" xsi:type="array">
          <item name="dataScope" xsi:type="string">data</item>
          <item name="namespace" xsi:type="string">engraving_scheduler_form</item>
          </item>
          <item name="template" xsi:type="string">templates/form/collapsible</item>
          <item name="buttons" xsi:type="array">
          <item name="back" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditBackButton</item>
          <item name="delete" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditDeleteButton</item>
          <item name="save" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveButton</item>
          <item name="save_and_continue" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveAndContinueButton</item>
          </item>
          </argument>
          <dataSource name="scheduler_form_data_source">
          <argument name="dataProvider" xsi:type="configurableObject">
          <argument name="class" xsi:type="string">VendorModuleModelSchedulerDataProvider</argument>
          <argument name="name" xsi:type="string">scheduler_form_data_source</argument>
          <argument name="primaryFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="requestFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="submit_url" path="*/*/save" xsi:type="url"/>
          </item>
          </argument>
          </argument>
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
          </item>
          </argument>
          </dataSource>
          <fieldset name="General">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="label" xsi:type="string"/>
          </item>
          </argument>
          <field name="label">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="dataType" xsi:type="string">text</item>
          <item name="label" translate="true" xsi:type="string">Title</item>
          <item name="formElement" xsi:type="string">input</item>
          <item name="source" xsi:type="string">Scheduler</item>
          <item name="sortOrder" xsi:type="number">10</item>
          <item name="dataScope" xsi:type="string">label</item>
          <item name="validation" xsi:type="array">
          <item name="required-entry" xsi:type="boolean">true</item>
          </item>
          </item>
          </argument>
          </field>
          </fieldset>
          </form>





          share|improve this answer













          Using dataPersistor to get Form data, thought you're using getSession



          $data = $this->getSession()->getFormData();


          Save action



          <?php


          namespace VendorModuleControllerAdminhtmlScheduler;

          use MagentoFrameworkExceptionLocalizedException;

          class Save extends MagentoBackendAppAction


          protected $dataPersistor;

          /**
          * @param MagentoBackendAppActionContext $context
          * @param MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          */
          public function __construct(
          MagentoBackendAppActionContext $context,
          MagentoFrameworkAppRequestDataPersistorInterface $dataPersistor
          )
          $this->dataPersistor = $dataPersistor;
          parent::__construct($context);


          /**
          * Save action
          *
          * @return MagentoFrameworkControllerResultInterface
          */
          public function execute()

          /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
          $resultRedirect = $this->resultRedirectFactory->create();
          $data = $this->getRequest()->getPostValue();
          if ($data)
          $id = $this->getRequest()->getParam('scheduler_id');

          $model = $this->_objectManager->create('VendorModuleModelScheduler')->load($id);
          if (!$model->getId() && $id)
          $this->messageManager->addErrorMessage(__('This Scheduler no longer exists.'));
          return $resultRedirect->setPath('*/*/');


          $model->setData($data);

          try

          $model->save();
          $this->messageManager->addSuccessMessage(__('You saved the Scheduler.'));
          $this->dataPersistor->clear('engraving_scheduler');

          if ($this->getRequest()->getParam('back'))
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $model->getId()]);

          return $resultRedirect->setPath('*/*/');
          catch (LocalizedException $e)
          $this->messageManager->addErrorMessage($e->getMessage());
          catch (Exception $e)
          $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Scheduler.'));


          $this->dataPersistor->set('engraving_scheduler', $data);
          return $resultRedirect->setPath('*/*/edit', ['scheduler_id' => $this->getRequest()->getParam('scheduler_id')]);

          return $resultRedirect->setPath('*/*/');




          DataProvider



          <?php


          namespace VendorModuleModelScheduler;

          use VendorModuleModelResourceModelSchedulerCollectionFactory;
          use MagentoFrameworkAppRequestDataPersistorInterface;

          class DataProvider extends MagentoUiDataProviderAbstractDataProvider


          protected $dataPersistor;

          protected $loadedData;
          protected $collection;


          /**
          * Constructor
          *
          * @param string $name
          * @param string $primaryFieldName
          * @param string $requestFieldName
          * @param CollectionFactory $collectionFactory
          * @param DataPersistorInterface $dataPersistor
          * @param array $meta
          * @param array $data
          */
          public function __construct(
          $name,
          $primaryFieldName,
          $requestFieldName,
          CollectionFactory $collectionFactory,
          DataPersistorInterface $dataPersistor,
          array $meta = [],
          array $data = []
          )
          $this->collection = $collectionFactory->create();
          $this->dataPersistor = $dataPersistor;
          parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);


          /**
          * Get data
          *
          * @return array
          */
          public function getData()

          if (isset($this->loadedData))
          return $this->loadedData;

          $items = $this->collection->getItems();
          foreach ($items as $model)
          $this->loadedData[$model->getId()] = $model->getData();

          $data = $this->dataPersistor->get('engraving_scheduler');

          if (!empty($data))
          $model = $this->collection->getNewEmptyItem();
          $model->setData($data);
          $this->loadedData[$model->getId()] = $model->getData();
          $this->dataPersistor->clear('engraving_scheduler');


          return $this->loadedData;




          ui form xml



           <?xml version="1.0" ?>
          <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="provider" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          <item name="deps" xsi:type="string">engraving_scheduler_form.scheduler_form_data_source</item>
          </item>
          <item name="label" translate="true" xsi:type="string">General Information</item>
          <item name="config" xsi:type="array">
          <item name="dataScope" xsi:type="string">data</item>
          <item name="namespace" xsi:type="string">engraving_scheduler_form</item>
          </item>
          <item name="template" xsi:type="string">templates/form/collapsible</item>
          <item name="buttons" xsi:type="array">
          <item name="back" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditBackButton</item>
          <item name="delete" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditDeleteButton</item>
          <item name="save" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveButton</item>
          <item name="save_and_continue" xsi:type="string">VendorModuleBlockAdminhtmlSchedulerEditSaveAndContinueButton</item>
          </item>
          </argument>
          <dataSource name="scheduler_form_data_source">
          <argument name="dataProvider" xsi:type="configurableObject">
          <argument name="class" xsi:type="string">VendorModuleModelSchedulerDataProvider</argument>
          <argument name="name" xsi:type="string">scheduler_form_data_source</argument>
          <argument name="primaryFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="requestFieldName" xsi:type="string">scheduler_id</argument>
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="submit_url" path="*/*/save" xsi:type="url"/>
          </item>
          </argument>
          </argument>
          <argument name="data" xsi:type="array">
          <item name="js_config" xsi:type="array">
          <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
          </item>
          </argument>
          </dataSource>
          <fieldset name="General">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="label" xsi:type="string"/>
          </item>
          </argument>
          <field name="label">
          <argument name="data" xsi:type="array">
          <item name="config" xsi:type="array">
          <item name="dataType" xsi:type="string">text</item>
          <item name="label" translate="true" xsi:type="string">Title</item>
          <item name="formElement" xsi:type="string">input</item>
          <item name="source" xsi:type="string">Scheduler</item>
          <item name="sortOrder" xsi:type="number">10</item>
          <item name="dataScope" xsi:type="string">label</item>
          <item name="validation" xsi:type="array">
          <item name="required-entry" xsi:type="boolean">true</item>
          </item>
          </item>
          </argument>
          </field>
          </fieldset>
          </form>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 4:23









          Tuyen NguyenTuyen Nguyen

          343111




          343111












          • Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

            – Langley
            Nov 15 '18 at 8:04

















          • Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

            – Langley
            Nov 15 '18 at 8:04
















          Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

          – Langley
          Nov 15 '18 at 8:04





          Yes DataPersistor is a better way of doing this (the question is quite dated), but following up with ObjectManager use is not so good.

          – Langley
          Nov 15 '18 at 8:04

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f132707%2fdata-population-in-ui-form%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          六本木駅

          Integral that is continuous and looks like it converges to a geometric seriesTesting if a geometric series converges by taking limit to infinitySummation of arithmetic-geometric series of higher orderGeometric series with polynomial exponentHow to Recognize a Geometric SeriesShowing an integral equality with series over the integersDiscontinuity of a series of continuous functionsReasons why a Series ConvergesSum of infinite geometric series with two terms in summationUsing geometric series for computing IntegralsLimit of geometric series sum when $r = 1$

          Joseph Lister