staempfli / magento2-code-generator

Code generator for Magento 2
250 stars 58 forks source link

Error on edit if identifier not set #19

Closed gfernandes410 closed 4 years ago

gfernandes410 commented 6 years ago

Hi Guys,

First of all, nice project and thank you for all suport!

If you not set identifier on create a register, you will get an error on edit this register. My suggestion is on VENDOR\MODULE\Controller\Adminhtml\ENTITY**Save.php** before you save, make an validation and if the identifier is null make same random.

Some thing like that:

            if($objectInstance->getData('identifier') == null) {
                $objectInstance->setIdentifier($this->generateRandomString());
            }
gfernandes410 commented 5 years ago

@jalogut have you seen this PR?

jalogut commented 4 years ago

Hi @gfernandes410 I merged your PR and created a new version 1.11.1. Thanks for your contribution and sorry for the delay.

UpSage commented 4 years ago

Hi . It does not seem to work if I have a UI component tab on the form. It does not save and Im getting this error:

Error: Call to undefined method Vendor\Module\Controller\Adminhtml\Module\Save\Interceptor::generateRandomString()

Please help. Thank you

<fieldset name="main_fieldset">

  <settings>
   <label translate="true">Tab 1</label>
  </settings>

  <field name="store_id">
   <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
     <item name="visible" xsi:type="boolean">true</item>
     <item name="dataType" xsi:type="string">number</item>
     <item name="formElement" xsi:type="string">hidden</item>
     <!--<item name="default" xsi:type="number">0</item>-->
     <item name="sortOrder" xsi:type="string">10</item>
     <item name="source" xsi:type="string">main_fieldset</item>
    </item>
   </argument>
  </field>

  <field name="entity_id">
   <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
     <item name="visible" xsi:type="boolean">false</item>
     <item name="dataType" xsi:type="string">text</item>
     <item name="formElement" xsi:type="string">input</item>
     <item name="source" xsi:type="string">main_fieldset</item>
    </item>
   </argument>
  </field>

  <field name="identifier">
   <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
     <item name="visible" xsi:type="boolean">true</item>
     <item name="dataType" xsi:type="string">text</item>
     <item name="label" xsi:type="string">Identifier</item>
     <item name="formElement" xsi:type="string">input</item>
     <item name="source" xsi:type="string">main_fieldset</item>
     <item name="validation" xsi:type="array">
      <item name="required-entry" xsi:type="boolean">true</item>
     </item>
     <item name="sortOrder" xsi:type="number">10</item>
     <item name="scopeLabel" xsi:type="string">[GLOBAL]</item>
    </item>
   </argument>
  </field>

  <!-- Add your fields here -->

 </fieldset>
UpSage commented 4 years ago

@jalogut @gfernandes410 . Please help thanks