Showing posts with label extension. Show all posts
Showing posts with label extension. Show all posts

Wednesday, April 15, 2020

Add custom tab in logged user account in magento 2

Hello All,

Today I saw you How to create custom tab in logged in user account in magento 2.

Custom tab will display like this:



app\code\Chirag\Customproduct\registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Chirag_Customproduct',
    __DIR__
);


app\code\Chirag\Customproduct\etc\module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Chirag_Customproduct" setup_version="1.0.0" >
<sequence>
        <module name="Magento_Customer"/>
    </sequence>
</module>
</config>


app\code\Chirag\Customproduct\etc\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Model\Order\Pdf\Invoice"
                type="Czargroup\Pdfinvoice\Model\Order\Pdf\Invoice"/>
</config>


app\code\Chirag\Customproduct\etc\frontend\routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="customproduct" frontName="customproduct">
            <module name="Chirag_Customproduct" />
        </route>
    </router>
</config>


app\code\Chirag\Customproduct\Controller\Customer\Index.php

<?php
namespace Chirag\Customproduct\Controller\Customer; 
class Index extends \Magento\Framework\App\Action\Action {
 
 public function execute() {
 
    $this->_view->loadLayout();
    $this->_view->renderLayout();
  }
 
}
?> 


app\code\Chirag\Customproduct\view\frontend\layout\customer_account.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceBlock name="customer_account_navigation">
         <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-customproduct">
            <arguments>
               <argument name="path" xsi:type="string">customproduct/customer/index</argument>
               <argument name="label" xsi:type="string">Custom Product</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page> 


app\code\Chirag\Customproduct\view\frontend\layout\customproduct_customer_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<body>
    <referenceBlock name="page.main.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">Custom Product</argument>
            </action>
     </referenceBlock>
     <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="customproduct" template="Chirag_Customproduct::customproduct.phtml">
        </block>
    </referenceContainer>
</body>
</page>   


app\code\Chirag\Customproduct\view\frontend\templates\customproduct.phtml

<?php
 // Add Some Code Here 
echo "This is custom Product List";
?> 


Wednesday, March 18, 2020

Display custom options in admin side in sales order details which created by programmatically

In the previous post, I explain how to create custom options by programmatically. Now I saw you how to display it in admin order details.
Here I saw you how to display custom options at admin sales order details which are created by programmatically.





Now created code in this manner.

\Czargroup\Addtocart\registration.php


<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Czargroup_Addtocart',
    __DIR__
);



\Czargroup\Addtocart\etc\module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Czargroup_Addtocart" setup_version="1.0.1" />
</config>



\Czargroup\Addtocart\etc\events.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="sales_model_service_quote_submit_before">
        <observer name="unique_name" instance="Czargroup\Addtocart\Observer\OrderItemAdditionalOptions" />
    </event>
</config>



\Czargroup\Addtocart\etc\frontend\routes.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route frontName="addtocart" id="addtocart">
            <module name="Czargroup_Addtocart"/>
        </route>
    </router>
</config>



\Czargroup\Addtocart\Controller\Index\Index.php

<?php
namespace Czargroup\Addtocart\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Data\Form\FormKey;
use Magento\Checkout\Model\Cart;
use Magento\Catalog\Model\Product;
use Magento\Framework\View\Result\PageFactory;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $formKey;  
    protected $cart;
    protected $product;
    protected $_pageFactory;
    protected $_session;
    protected $serializer;
    protected $ProductRepository;

    protected $_responseFactory;

    public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\Data\Form\FormKey $formKey,
    \Magento\Checkout\Model\Cart $cart,
    \Magento\Catalog\Model\Product $product,
    \Magento\Catalog\Model\ProductRepository $ProductRepository,
    \Magento\Customer\Model\Session $session,
    \Magento\Framework\Serialize\SerializerInterface $serializer,
    \Magento\Framework\View\Result\PageFactory $PageFactory,
    \Magento\Framework\App\ResponseFactory $responseFactory,
    array $data = []) {
        $this->_responseFactory = $responseFactory;

        $this->formKey = $formKey;
        $this->_pageFactory = $PageFactory;
        $this->cart = $cart;
        $this->serializer = $serializer;
        $this->product = $product;
        $this->ProductRepository = $ProductRepository;
        $this->_session = $session;   
        parent::__construct($context);
    }

    public function execute()
    {
      $page = $this->_pageFactory->create();
      $productId =1;
      $id = $this->_session->getId();
      $additionalOptions['firstnamesku'] = [
                'label' => 'First Name',
                'value' => 'chirag',
            ];
      $additionalOptions['lnamesku'] = [
                'label' => 'Last Name',
                'value' => 'parmar',
            ];
      $additionalOptions['emailidsku'] = [
                'label' => 'Email ID',
                'value' => 'chirag@gmail.com',
            ];
      $additionalOptions['phonenosku'] = [
                'label' => 'Phone No',
                'value' => '1234567890',
            ];
    
      if(!$this->_session->isLoggedIn()){
      $params = array(
                    'form_key' => $this->formKey->getFormKey(),
                    'product' => $productId, //product Id
                    'qty'   =>1 //quantity of product
            );  
       }else{
            $params = array(
                    'form_key' => $this->formKey->getFormKey(),
                    'product' => $productId, //product Id
                    'qty'   =>1, //quantity of product
                    'customer_id'   =>$id
            );
    }          
    //Load the product based on productID  
    $_product = $this->ProductRepository->getById($productId);
    $_product->addCustomOption('additional_options', $this->serializer->serialize($additionalOptions));
    $this->cart->addProduct($_product, $params)->getParentItem();
    $this->cart->save();
    //return $page;
    $message = "Product have been successfully added to your Shopping Cart.";
    $this->messageManager->addSuccess($message);
    $accUrl = $this->_url->getUrl('checkout/cart/');
    $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
    $this->setRefererUrl($accUrl);
  }
}



\Czargroup\Addtocart\Observer\OrderItemAdditionalOptions.php

<?php
namespace Czargroup\Addtocart\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Unserialize\Unserialize;
use \Magento\Framework\Serialize\Serializer\Json;

class OrderItemAdditionalOptions implements ObserverInterface
{
    /**
     * @param \Magento\Framework\Event\Observer $observer
     */
    protected $Unserialize;
    protected $Serializer;

    public function __construct(
        Unserialize $Unserialize,
        Json $Json
    ){
        $this->Unserialize = $Unserialize;
        $this->Serializer = $Json;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        try {
            $quote = $observer->getQuote();
            $order = $observer->getOrder();
            $quoteItems = [];

            // Map Quote Item with Quote Item Id
            foreach ($quote->getAllVisibleItems() as $quoteItem) {
                $quoteItems[$quoteItem->getId()] = $quoteItem;
            }

            foreach ($order->getAllVisibleItems() as $orderItem) {
                $quoteItemId = $orderItem->getQuoteItemId();
                $quoteItem = $quoteItems[$quoteItemId];
                $additionalOptions = $quoteItem->getOptionByCode('additional_options');
                // Get Order Item's other options
                $options = $orderItem->getProductOptions();
                // Set additional options to Order Item
                if($this->isSerialized($additionalOptions->getValue())){
                    $options['options'] = $this->Unserialize->unserialize($additionalOptions->getValue());
                }else{
                    $options['options'] = $this->Serializer->unserialize($additionalOptions->getValue());
                }
                    $orderItem->setProductOptions($options);
            }
        }

        catch (\Exception $e) {
            // catch error if any
            echo $e->getMessage();
        }
    }
    private function isSerialized($value)
    {
        return (boolean) preg_match('/^((s|i|d|b|a|O|C):|N;)/', $value);
    }
}
?>

Now run commands : 

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento c:f


now hit url like this:
yourwebsite.com/addtocart
You will get this window and message:


Now click on Proceed to Checkout. Place order successfully.

Go to admin->sales-> order details page
You can see this data.


Thursday, March 5, 2020

magento 2 add product to cart programmatically with custom options

Hello

Here I explain to you how to add product to cart programmatically with custom options.

First, create custom options from the Magento admin.


 Now go to app->code->Czar->Cart


 registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Czar_Cart',
    __DIR__
);


etc -> module.xml

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Czar_Cart" setup_version="1.0.0">
    </module>
</config>


etc -> routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="add" frontName="add">
            <module name="Czar_Cart"/>
        </route>
    </router>
</config>


Controller->Index->Index.php


<?php
namespace Czar\Cart\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Data\Form\FormKey;
use Magento\Checkout\Model\Cart;
use Magento\Catalog\Model\Product;

class Index extends Action
{
protected $formKey;  
protected $cart;
protected $product;
protected $_pageFactory;
protected $_session;
protected $serializer;
protected $ProductRepository;

protected $_responseFactory;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Data\Form\FormKey $formKey,
\Magento\Checkout\Model\Cart $cart,
\Magento\Catalog\Model\Product $product,
 \Magento\Catalog\Model\ProductRepository $ProductRepository,
\Magento\Customer\Model\Session $session,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Framework\View\Result\PageFactory $PageFactory,
\Magento\Framework\App\ResponseFactory $responseFactory,
array $data = []) {
    $this->_responseFactory = $responseFactory;

    $this->formKey = $formKey;
    $this->_pageFactory = $PageFactory;
    $this->cart = $cart;
    $this->serializer = $serializer;
    $this->product = $product;
    $this->ProductRepository = $ProductRepository;
    $this->_session = $session;   
    parent::__construct($context);
}

public function execute()
 {

  $page = $this->_pageFactory->create();
  $productId =1;
  $id = $this->_session->getId();
  $additionalOptions['firstnamesku'] = [
            'label' => 'First Name',
            'value' => 'chirag',
        ];
  $additionalOptions['lnamesku'] = [
            'label' => 'Last Name',
            'value' => 'parmar',
        ];
  $additionalOptions['emailidsku'] = [
            'label' => 'Email ID',
            'value' => 'chirag@czargroup.net',
        ];
  $additionalOptions['phonenosku'] = [
            'label' => 'Phone No',
            'value' => '1234567890',
        ];

  if(!$this->_session->isLoggedIn()){
  $params = array(
                'form_key' => $this->formKey->getFormKey(),
                'product' => $productId, //product Id
                'qty'   =>1 //quantity of product
                             
            );  
   }else{
           $params = array(
                'form_key' => $this->formKey->getFormKey(),
                'product' => $productId, //product Id
                'qty'   =>1, //quantity of product
                'customer_id'   =>$id
                               
            );
   }          
    //Load the product based on productID  
    $_product = $this->ProductRepository->getById($productId);
   
    $_product->addCustomOption('additional_options', $this->serializer->serialize($additionalOptions));
    $this->cart->addProduct($_product, $params);
    $this->cart->save();
    //return $page;
    $message = "Product have been successfully added to your Shopping Cart.";
    $this->messageManager->addSuccess($message);
    $accUrl = $this->_url->getUrl('checkout/cart/');
    $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
    $this->setRefererUrl($accUrl);
  }
}

Now run commands : 

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento c:f


now hit url like this:
yourwebsite.com/add

It will display result like this:-


 

Wednesday, March 4, 2020

How to uninstall and remove a Magento 2 extension ( manual vs composer )

Hello 
Here I saw you how to remove the extension by manually or composer.

A. Manual Uninstall
Step 1: Connect via SSH to the root of your magento installation (this is the folder that has the app folder in it) and check the list of all modules including their enable/disable status
·         php bin/magento module:status

Step 2:  Disable the module by executing below commands:
·         php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
·         php bin/magento setup:upgrade

Step 3: Remove extension files
·         cd app/code/<ExtensionProvider>/
·         rm -rf <ExtensionName>
!Note: If you are using more extensions from the same provider make sure not to remove the shared extension, most providers use a shared extension or dependency pack as a base for all their extensions.
  
Example: Let assume you are using Chirag Outofstock Extension and you want to uninstall it and remove all associated files:
·         php bin/magento module:disable Chirag_Outofstock --clear-static-content
·         php bin/magento setup:upgrade
·         cd app/code/Chirag/
·         rm -rf Outofstock

Important: If you are using other Outofstock extensions make sure not to remove the 'Backend' shared extension as it is used by the rest of Outofstock installed extensions. If you do not have any other Outofstock extensions it is safe to uninstall and remove also the 'Backend' extension.
  

B. Composer Uninstall
Step 1: Connect via SSH to the root of your magento installation (this is the folder that has the app folder in it) and check the list of all modules including their enable/disable status
·         php bin/magento module:status

 Step 2: Disable the module by executing below commands::
·         php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
·         php bin/magento setup:upgrade
·         composer remove VendorName/VendorExtensionRepository

Note: you can find the exact match for ExtensionProvider and ExtensionName in composer.json file associated with the extension.
Note2: you can find the exact match for VendorName and VendorExtension in composer.json file associated with the extension.or under yourmagentoinstallation/com/vendor/<VendorName>/<VendorExtension>
Note3: You may be asked for composer username and password when uninstalling, you will be able to find them under var/composer_home/auth.json

Example: Let assume you are using Chirag Outofstock Extension and you want to uninstall it and remove all associated files. First thing you should disable this extension, run the setup upgrade and finally remove the files via composer:
·         php bin/magento module:disable Chirag_Outofstock  --clear-static-content
·         composer remove chirag/m2-chirag_outofstock
·         php bin/magento setup:upgrade

Important: If you are using other Outofstock extensions make sure not to remove the 'Backend' shared extension as it is used by the rest of Outofstock installed extensions. If you do not have any other Outofstock extensions it is safe to uninstall and remove also the 'Backend' extension.

Friday, December 20, 2019

Magento 2 extension for admin events management

Hello.

Here I explain  CRUD for backend side in magento 2. CRUD module for admin with UI Component

Create this type of files and folders structure.

 


First create registration.php and composer.json

Chirag->Events->registration.php
 <?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Chirag_Events',
    __DIR__
);

Chirag->Events->composer.json
 {
    "name": "chirag/module-events",
    "description": "",
    "type": "magento2-module",
    "license": "proprietary",
    "authors": [
        {
            "email": "chirag@czargroup.net",
            "name": "Czargroup"
        }
    ],
    "minimum-stability": "dev",
    "require": {},
    "autoload": {
        "psr-4": {
            "Chirag\\Events\\": ""
        },
        "files": [
            "registration.php"
        ]
    }
}

Chirag->Events->etc->module.xml

<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Chirag_Events" setup_version="1.0.1" />
</config>

Chirag->Events->etc->di.xml

<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="ChiragEventsGridFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="ChiragEventsGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Chirag\Events\Model\ResourceModel\Events\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">ChiragEventsGridFilterPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="Chirag\Events\Model\ResourceModel\Events\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">chirag_events_table</argument>
            <argument name="resourceModel" xsi:type="string">Chirag\Events\Model\ResourceModel\Events</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="chirag_events_index_listing_data_source" xsi:type="string">Chirag\Events\Model\ResourceModel\Events\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

 Chirag->Events->etc->adminhtml->menu.xml

<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Backend/etc/menu.xsd">
    <menu>
        <add id="chirag_events::core" title="Events Create" module="Chirag_Events" sortOrder="90" resource="Chirag_Events::sample"/>
        <add id="chirag_events::test" title="Display All Events" module="Chirag_Events" sortOrder="10" parent="chirag_events::core" action="chirag_events/items/" resource="Chirag_Events::items"/>
    </menu>
</config>


  Chirag->Events->etc->adminhtml->routes.xml
<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="admin">
        <route id="chirag_events" frontName="chirag_events">
            <module name="Chirag_Events" />
        </route>
    </router>
</config>

Now create setup files.
 Chirag->Events->Setup->InstallSchema.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallSchema implements InstallSchemaInterface
{
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        /**
         * Creating table chirag_events_table
         */
        $table = $installer->getConnection()->newTable(
            $installer->getTable('chirag_events_table')
        )->addColumn(
            'entity_id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
            'Chirag Events Id'
        )->addColumn(
            'reason',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            ['nullable' => false],
            'Reason'
        )->addColumn(
            'date',
            \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
            null,
            ['nullable' => false],
            'Choose Date'
        )->addColumn(
            'status',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            11,
            ['nullable' => true,'default' => 1],
            'Status'
        )->addColumn(
            'created_at',
            \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
            null,
            ['nullable' => false],
            'Created At'
        )->addColumn(
            'updated_at',
            \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
            null,
            ['nullable' => false],
            'Updated At'
        )->setComment(
            'Chirag Events Table'
        );
        $installer->getConnection()->createTable($table);
        $installer->endSetup();
    }
}

 Chirag->Events->Setup->UpgradeSchema.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

/**
 * @codeCoverageIgnore
 */
class UpgradeSchema implements UpgradeSchemaInterface
{
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        /**
         * Creating table chirag_events_table
         */
        if (version_compare($context->getVersion(), '1.0.1') < 0) {
            $table = $installer->getConnection()->newTable(
                $installer->getTable('chirag_events_table')
            )->addColumn(
                'entity_id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                'Chirag Events Id'
            )->addColumn(
                'reason',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                ['nullable' => false],
                'Reason'
            )->addColumn(
                'date',
                \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                null,
                ['nullable' => false],
                'Choose Date'
            )->addColumn(
                'status',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                11,
                ['nullable' => true,'default' => 1],
                'Status'
            )->addColumn(
                'created_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false],
                'Created At'
            )->addColumn(
                'updated_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false],
                'Updated At'
            )->setComment(
                'Chirag Events Table'
            );
            $installer->getConnection()->createTable($table);
        }
        $installer->endSetup();
    }
}

 Chirag->Events->Model->Events.php
<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Model;

use Magento\Framework\Model\AbstractModel;

class Events extends AbstractModel
{
    /**
     * Define resource model
     */
    protected function _construct()
    {
        $this->_init('Chirag\Events\Model\ResourceModel\Events');
    }
}

Chirag->Events->Model->Source->Status.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Model\Source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
use Magento\Framework\Data\OptionSourceInterface;

/**
 * Item status functionality model
 */
class Status extends AbstractSource implements SourceInterface, OptionSourceInterface
{
    /**#@+
     * Item Status values
     */
    const STATUS_ENABLED = 1;

    const STATUS_DISABLED = 0;

    /**#@-*/

    /**
     * Retrieve option array
     *
     * @return string[]
     */
    public static function getOptionArray()
    {
        return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
    }

    /**
     * Retrieve option array with empty value
     *
     * @return string[]
     */
    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }
}


 Chirag->Events->Model->ResourceModel->Events.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Model\ResourceModel;

class Events extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    /**
     * Define main table
     */
    protected function _construct()
    {
        $this->_init('chirag_events_table', 'entity_id');   //here "chirag_events_table" is table name and "entity_id" is the primary key of custom table
    }
}

 Chirag->Events->Model->ResourceModel->Events->Collection.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Model\ResourceModel\Events;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    protected $_idFieldName = 'entity_id';
    /**
     * Define model & resource model
     */
    protected function _construct()
    {
        $this->_init(
            'Chirag\Events\Model\Events',
            'Chirag\Events\Model\ResourceModel\Events'
        );
    }
}

Chirag->Events->Controller->Adminhtml->Items.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\MediaStorage\Model\File\UploaderFactory;
use Magento\Framework\Image\AdapterFactory;
use Magento\Framework\Filesystem;
/**
 * Items controller
 */
abstract class Items extends \Magento\Backend\App\Action
{
    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry;

    /**
     * @var \Magento\Backend\Model\View\Result\ForwardFactory
     */
    protected $resultForwardFactory;

    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $resultPageFactory;

    protected $uploaderFactory;
    protected $adapterFactory;
    protected $filesystem;

    /**
     * Initialize Group Controller
     *
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\Registry $coreRegistry
     * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        DirectoryList $directoryList,
        UploaderFactory $uploaderFactory,
        AdapterFactory $adapterFactory,
        Filesystem $filesystem,
        \Magento\Framework\Filesystem\Driver\File $file
    ) {
        $this->_coreRegistry = $coreRegistry;
        parent::__construct($context);
        $this->resultForwardFactory = $resultForwardFactory;
        $this->resultPageFactory = $resultPageFactory;
        $this->directoryList = $directoryList;
        $this->uploaderFactory = $uploaderFactory;
        $this->adapterFactory = $adapterFactory;
        $this->filesystem = $filesystem;
        $this->_file = $file;
    }

    /**
     * Initiate action
     *
     * @return this
     */
    protected function _initAction()
    {
        $this->_view->loadLayout();
        $this->_setActiveMenu('Chirag_Events::items')->_addBreadcrumb(__('Items'), __('Items'));
        return $this;
    }

    /**
     * Determine if authorized to perform group actions.
     *
     * @return bool
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Chirag_Events::items');
    }
}



Chirag->Events->Controller->Adminhtml->Items->Index.php
<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

class Index extends \Chirag\Events\Controller\Adminhtml\Items
{
    /**
     * Items list.
     *
     * @return \Magento\Backend\Model\View\Result\Page
     */
    public function execute()
    {
        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->setActiveMenu('Chirag_Events::test');
        $resultPage->getConfig()->getTitle()->prepend(__('Create Event Admin Page'));
        $resultPage->addBreadcrumb(__('Manage'), __('Manage'));
        $resultPage->addBreadcrumb(__('Date'), __('Date'));
        return $resultPage;
    }
}


 Chirag->Events->Controller->Adminhtml->Items->NewAction.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

class NewAction extends \Chirag\Events\Controller\Adminhtml\Items
{

    public function execute()
    {
        $this->_forward('edit');
    }
}




 Chirag->Events->Controller->Adminhtml->Items->Edit.php
<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

class Edit extends \Chirag\Events\Controller\Adminhtml\Items
{

    public function execute()
    {
        $id = $this->getRequest()->getParam('id');
       
        $model = $this->_objectManager->create('Chirag\Events\Model\Events');

        if ($id) {
            $model->load($id);
            if (!$model->getId()) {
                $this->messageManager->addError(__('This event no longer exists.'));
                $this->_redirect('chirag_events/*');
                return;
            }
        }
        // set entered data if was error when we do save
        $data = $this->_objectManager->get('Magento\Backend\Model\Session')->getPageData(true);
        if (!empty($data)) {
            $model->addData($data);
        }
        $this->_coreRegistry->register('current_chirag_events_items', $model);
        $this->_initAction();
        if ($model->getId()) {
            $title = __('Edit Event');
        } else {
            $title = __('New Event Create Form');
        }
        $this->_view->getPage()->getConfig()->getTitle()->prepend($title);
        $this->_view->getLayout()->getBlock('items_items_edit');
        $this->_view->renderLayout();
    }
}



 Chirag->Events->Controller->Adminhtml->Items->Save.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

class Save extends \Chirag\Events\Controller\Adminhtml\Items
{
    public function execute()
    {
        if ($this->getRequest()->getPostValue()) {
            try {
                $model = $this->_objectManager->create('Chirag\Events\Model\Events');
                $data = $this->getRequest()->getPostValue();
                if(isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
                    try{
                        $uploaderFactory = $this->uploaderFactory->create(['fileId' => 'image']);
                        $uploaderFactory->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
                        $imageAdapter = $this->adapterFactory->create();
                        $uploaderFactory->addValidateCallback('custom_image_upload',$imageAdapter,'validateUploadFile');
                        $uploaderFactory->setAllowRenameFiles(true);
                        $uploaderFactory->setFilesDispersion(true);
                        $mediaDirectory = $this->filesystem->getDirectoryRead($this->directoryList::MEDIA);
                        $destinationPath = $mediaDirectory->getAbsolutePath('chirag/events');
                        $result = $uploaderFactory->save($destinationPath);
                        if (!$result) {
                            throw new LocalizedException(
                                __('File cannot be saved to path: $1', $destinationPath)
                            );
                        }
                       
                        $imagePath = 'chirag/events'.$result['file'];
                        $data['image'] = $imagePath;
                    } catch (\Exception $e) {
                    }
                }
                if(isset($data['image']['delete']) && $data['image']['delete'] == 1) {
                    $mediaDirectory = $this->filesystem->getDirectoryRead($this->directoryList::MEDIA)->getAbsolutePath();
                    $file = $data['image']['value'];
                    $imgPath = $mediaDirectory.$file;
                    if ($this->_file->isExists($imgPath))  {
                        $this->_file->deleteFile($imgPath);
                    }
                    $data['image'] = NULL;
                }
                if (isset($data['image']['value'])){
                    $data['image'] = $data['image']['value'];
                }
                $inputFilter = new \Zend_Filter_Input(
                    [],
                    [],
                    $data
                );
                $data = $inputFilter->getUnescaped();
                $id = $this->getRequest()->getParam('id');
                if ($id) {
                    $model->load($id);
                    if ($id != $model->getId()) {
                        throw new \Magento\Framework\Exception\LocalizedException(__('The wrong item is specified.'));
                    }
                }
               
                $timezone = $this->_objectManager->create('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
                $fromTz = $timezone->getConfigTimezone();
                $toTz = $timezone->getDefaultTimezone();
                $date = new \DateTime($data['date'], new \DateTimeZone($fromTz));
                $date->setTimezone(new \DateTimeZone($toTz));
                $data['date'] = $date->format('m/d/Y H:i:s');
               
                $timezone = $this->_objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
                $data['updated_at'] = $timezone->gmtDate();
               
                $model->setData($data);
                $session = $this->_objectManager->get('Magento\Backend\Model\Session');
                $session->setPageData($model->getData());
                $model->save();
                $this->messageManager->addSuccess(__('You saved the event.'));
                $session->setPageData(false);
                if ($this->getRequest()->getParam('back')) {
                    $this->_redirect('chirag_events/*/edit', ['id' => $model->getId()]);
                    return;
                }
                $this->_redirect('chirag_events/*/');
                return;
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $this->messageManager->addError($e->getMessage());
                $id = (int)$this->getRequest()->getParam('id');
                if (!empty($id)) {
                    $this->_redirect('chirag_events/*/edit', ['id' => $id]);
                } else {
                    $this->_redirect('chirag_events/*/new');
                }
                return;
            } catch (\Exception $e) {
                $this->messageManager->addError(
                    __('Something went wrong while saving the event data. Please review the error log.')
                );
                $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
                $this->_objectManager->get('Magento\Backend\Model\Session')->setPageData($data);
                $this->_redirect('chirag_events/*/edit', ['id' => $this->getRequest()->getParam('id')]);
                return;
            }
        }
        $this->_redirect('chirag_events/*/');
    }
}


 Chirag->Events->Controller->Adminhtml->Items->MassStatus.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
use Chirag\Events\Model\ResourceModel\Events\CollectionFactory;

class MassStatus extends \Magento\Backend\App\Action
{
    /**
     * @var Filter
     */
    protected $filter;

    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;

    /**
     * @param Context $context
     * @param Filter $filter
     * @param CollectionFactory $collectionFactory
     */
    public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
    {
        $this->filter = $filter;
        $this->collectionFactory = $collectionFactory;
        parent::__construct($context);
    }

    /**
     * Execute action
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     * @throws \Magento\Framework\Exception\LocalizedException|\Exception
     */
    public function execute()
    {
        $collection = $this->filter->getCollection($this->collectionFactory->create());
        $collectionSize = $collection->getSize();

        foreach ($collection as $record) {
            $record->setStatus($this->getRequest()->getParam('status'))->save();
        }
        if($this->getRequest()->getParam('status') == 1){$status = 'enabled';}else{$status = 'disabled';}
        $this->messageManager->addSuccess(__('A total of %1 record(s) have been '.$status, $collectionSize));

        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('*/*/');
    }
}


 Chirag->Events->Controller->Adminhtml->Items->Delete.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

class Delete extends \Chirag\Events\Controller\Adminhtml\Items
{

    public function execute()
    {
        $id = $this->getRequest()->getParam('id');
        if ($id) {
            try {
                $model = $this->_objectManager->create('Chirag\Events\Model\Events');
                $model->load($id);
                $model->delete();
                $this->messageManager->addSuccess(__('You deleted the event.'));
                $this->_redirect('chirag_events/*/');
                return;
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $this->messageManager->addError($e->getMessage());
            } catch (\Exception $e) {
                $this->messageManager->addError(
                    __('We can\'t delete event right now. Please review the log and try again.')
                );
                $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
                $this->_redirect('chirag_events/*/edit', ['id' => $this->getRequest()->getParam('id')]);
                return;
            }
        }
        $this->messageManager->addError(__('We can\'t find a event to delete.'));
        $this->_redirect('chirag_events/*/');
    }
}


 Chirag->Events->Controller->Adminhtml->Items->MassDelete.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Controller\Adminhtml\Items;

use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
use Chirag\Events\Model\ResourceModel\Events\CollectionFactory;

class MassDelete extends \Magento\Backend\App\Action
{
    /**
     * @var Filter
     */
    protected $filter;

    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;

    /**
     * @param Context $context
     * @param Filter $filter
     * @param CollectionFactory $collectionFactory
     */
    public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
    {
        $this->filter = $filter;
        $this->collectionFactory = $collectionFactory;
        parent::__construct($context);
    }

    /**
     * Execute action
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     * @throws \Magento\Framework\Exception\LocalizedException|\Exception
     */
    public function execute()
    {
        $collection = $this->filter->getCollection($this->collectionFactory->create());
        $collectionSize = $collection->getSize();

        foreach ($collection as $record) {
            $record->delete();
        }

        $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));

        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('*/*/');
    }
}



 Chirag->Events->Block->Adminhtml->Items.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Block\Adminhtml;

class Items extends \Magento\Backend\Block\Widget\Grid\Container
{
    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_controller = 'items';
        $this->_headerText = __('Items');
        $this->_addButtonLabel = __('Add New Item1');
        parent::_construct();
    }
}

  Chirag->Events->Block->Adminhtml->Items->Edit.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Block\Adminhtml\Items;

class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry = null;

    /**
     * @param \Magento\Backend\Block\Widget\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Widget\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Initialize form
     * Add standard buttons
     * Add "Save and Continue" button
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_objectId = 'id';
        $this->_controller = 'adminhtml_items';
        $this->_blockGroup = 'Chirag_Events';

        parent::_construct();

        $this->buttonList->add(
            'save_and_continue_edit',
            [
                'class' => 'save',
                'label' => __('Save and Continue Edit'),
                'data_attribute' => [
                    'mage-init' => ['button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form']],
                ]
            ],
            10
        );
    }

    /**
     * Getter for form header text
     *
     * @return \Magento\Framework\Phrase
     */
    public function getHeaderText()
    {
        $item = $this->_coreRegistry->registry('current_chirag_events_items');
        if ($item->getId()) {
            return __("Edit Event '%1'", $this->escapeHtml($item->getReason()));
        } else {
            return __('New Event');
        }
    }
}

  Chirag->Events->Block->Adminhtml->Items->Edit->Form.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Block\Adminhtml\Items\Edit;

class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('events_items_form');
        $this->setTitle(__('Event Information'));
    }

    /**
     * Prepare form before rendering HTML
     *
     * @return $this
     */
    protected function _prepareForm()
    {
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create(
            [
                'data' => [
                    'id' => 'edit_form',
                    'action' => $this->getUrl('chirag_events/items/save'),
                    'method' => 'post',
                    'enctype' => 'multipart/form-data'
                ],
            ]
        );
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

 Chirag->Events->Block->Adminhtml->Items->Edit->Tabs.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Block\Adminhtml\Items\Edit;

class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('chirag_events_items_edit_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(__('Event'));
    }
}


   Chirag->Events->Block->Adminhtml->Items->Edit->Tabs->Main.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Block\Adminhtml\Items\Edit\Tab;

use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;

class Main extends Generic implements TabInterface
{
    protected $_wysiwygConfig;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Data\FormFactory $formFactory, 
        \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
        array $data = []
    )
    {
        $this->_wysiwygConfig = $wysiwygConfig;
        parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
     * {@inheritdoc}
     */
    public function getTabLabel()
    {
        return __('Event Information');
    }

    /**
     * {@inheritdoc}
     */
    public function getTabTitle()
    {
        return __('Event Information');
    }

    /**
     * {@inheritdoc}
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function isHidden()
    {
        return false;
    }

    /**
     * Prepare form before rendering HTML
     *
     * @return $this
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    protected function _prepareForm()
    {
        $model = $this->_coreRegistry->registry('current_chirag_events_items');
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create();
        $form->setHtmlIdPrefix('item_');
       
        $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
        $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
       
        $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Event Information')]);
        if ($model->getId()) {
            $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id']);
        }
        $fieldset->addField(
            'reason',
            'text',
            ['name' => 'reason', 'label' => __('Event Name'), 'title' => __('Event Name'), 'required' => true]
        );
        $fieldset->addField(
            'date',
            'date',
            ['name' => 'date', 'label' => __('Choose Date'), 'title' => __('Choose Date'), 'required' => true, 'date_format' => $dateFormat]
        );
        /* $fieldset->addField(
            'image',
            'image',
            [
                'name' => 'image',
                'label' => __('Image'),
                'title' => __('Image'),
                'required'  => false
            ]
        ); */
        /* $fieldset->addField(
            'status',
            'select',
            ['name' => 'status', 'label' => __('Status'), 'title' => __('Status'),  'options'   => [0 => 'Disable', 1 => 'Enable'], 'required' => true]
        ); */
        /* $fieldset->addField(
            'content',
            'editor',
            [
                'name' => 'content',
                'label' => __('Content'),
                'title' => __('Content'),
                'style' => 'height:26em;',
                'required' => true,
                'config'    => $this->_wysiwygConfig->getConfig(),
                'wysiwyg' => true
            ]
        ); */
       
        $form->setValues($model->getData());
        $this->setForm($form);
        return parent::_prepareForm();
    }
}


  Chirag->Events->view->adminhtml->layout->chirag_events_items_edit.xml

<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
        <referenceContainer name="left">
            <block class="Chirag\Events\Block\Adminhtml\Items\Edit\Tabs" name="chirag_events_items_edit_tabs">
                <block class="Chirag\Events\Block\Adminhtml\Items\Edit\Tab\Main" name="chirag_events_items_edit_tab_main"/>
                <action method="addTab">
                    <argument name="name" xsi:type="string">main_section</argument>
                    <argument name="block" xsi:type="string">chirag_events_items_edit_tab_main</argument>
                </action>
            </block>
        </referenceContainer>
        <referenceContainer name="content">
            <block class="Chirag\Events\Block\Adminhtml\Items\Edit" name="test_items_edit"/>
        </referenceContainer>
    </body>
</page>


   Chirag->Events->view->adminhtml->layout->chirag_events_items_index.xml

<?xml version="1.0"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <uiComponent name="chirag_events_index_listing"/>
        </referenceContainer>
    </body>
</page>

   Chirag->Events->view->adminhtml->ui_component->chirag_events_index_listing.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<listing 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">chirag_events_index_listing.chirag_events_index_listing_data_source</item>
            <item name="deps" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">chirag_events_index_listing_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Create an Event</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="chirag_events_index_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">ChiragEventsGridDataProvider</argument>
            <argument name="name" xsi:type="string">chirag_events_index_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
            <argument name="requestFieldName" xsi:type="string">entity_id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">entity_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <container name="listing_top">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="template" xsi:type="string">ui/grid/toolbar</item>
            </item>
        </argument>
        <bookmark name="bookmarks">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="storageConfig" xsi:type="array">
                        <item name="namespace" xsi:type="string">chirag_events_index_listing</item>
                    </item>
                </item>
            </argument>
        </bookmark>
        <component name="columns_controls">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="columnsData" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.chirag_events_index_listing_columns</item>
                    </item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
                    <item name="displayArea" xsi:type="string">dataGridActions</item>
                </item>
            </argument>
        </component>
        <filterSearch name="fulltext">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing_data_source</item>
                    <item name="chipsProvider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.listing_filters_chips</item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.bookmarks</item>
                        <item name="namespace" xsi:type="string">current.search</item>
                    </item>
                </item>
            </argument>
        </filterSearch>
        <filters name="listing_filters">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="columnsProvider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.chirag_events_index_listing_columns</item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.bookmarks</item>
                        <item name="namespace" xsi:type="string">current.filters</item>
                    </item>
                    <item name="templates" xsi:type="array">
                        <item name="filters" xsi:type="array">
                            <item name="select" xsi:type="array">
                                <item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
                                <item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                            </item>
                        </item>
                    </item>
                    <item name="childDefaults" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.listing_filters</item>
                        <item name="imports" xsi:type="array">
                            <item name="visible" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.chirag_events_index_listing_columns.${ $.index }:visible</item>
                        </item>
                    </item>
                </item>
            </argument>
        </filters>
        <massaction name="listing_massaction" component="Magento_Ui/js/grid/tree-massactions">
            <action name="delete">
                <settings>
                    <confirm>
                        <message translate="true">Delete selected items?</message>
                        <title translate="true">Delete items</title>
                    </confirm>
                    <url path="chirag_events/items/massDelete"/>
                    <type>delete</type>
                    <label translate="true">Delete</label>
                </settings>
            </action>
            <!-- <action name="status">
                <settings>
                    <type>status</type>
                    <label translate="true">Change status</label>
                    <actions>
                        <action name="0">
                            <type>enable</type>
                            <label translate="true">Enable</label>
                            <url path="chirag_events/items/massStatus">
                                <param name="status">1</param>
                            </url>
                        </action>
                        <action name="1">
                            <type>disable</type>
                            <label translate="true">Disable</label>
                            <url path="chirag_events/items/massStatus">
                                <param name="status">0</param>
                            </url>
                        </action>
                    </actions>
                </settings>
            </action> -->
        </massaction>
        <paging name="listing_paging">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.bookmarks</item>
                        <item name="namespace" xsi:type="string">current.paging</item>
                    </item>
                    <item name="selectProvider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.chirag_events_index_listing_columns.ids</item>
                </item>
            </argument>
        </paging>
    </container>
    <columns name="chirag_events_index_listing_columns">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="storageConfig" xsi:type="array">
                    <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.bookmarks</item>
                    <item name="namespace" xsi:type="string">current</item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="fieldAction" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.testing01_index_columns.actions</item>
                        <item name="target" xsi:type="string">applyAction</item>
                        <item name="params" xsi:type="array">
                            <item name="0" xsi:type="string">edit</item>
                            <item name="1" xsi:type="string">${ $.$data.rowIndex }</item>
                        </item>
                    </item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="provider" xsi:type="string">chirag_events_index_listing.chirag_events_index_listing.listing_top.bookmarks</item>
                        <item name="root" xsi:type="string">columns.${ $.index }</item>
                        <item name="namespace" xsi:type="string">current.${ $.storageConfig.root}</item>
                    </item>
                </item>
            </item>
        </argument>
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">entity_id</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="entity_id">
            <argument name="data" xsi:type="array">
                <item name="js_config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
                </item>
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">entity_id</item>
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="sorting" xsi:type="string">desc</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                </item>
            </argument>
        </column>
        <column name="reason">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Event Name</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                </item>
            </argument>
        </column>
        <column name="date" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <timezone>false</timezone>
                <dateFormat>MMM d, y</dateFormat>
                <filter>dateRange</filter>
                <editor>
                    <editorType>date</editorType>
                </editor>
                <dataType>date</dataType>
                <label translate="true">Choose Date</label>
            </settings>
        </column>
        <!-- <column name="author">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Author</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                </item>
            </argument>
        </column>
        <column name="image" class="Designnbuy\Dateportfolio\Ui\Component\Listing\Column\Thumbnail">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
                    <item name="sortable" xsi:type="boolean">false</item>
                    <item name="has_preview" xsi:type="string">1</item>                   
                    <item name="label" xsi:type="string" translate="true">Image</item>
                </item>
            </argument>
        </column>
        <column name="status">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Designnbuy\Dateportfolio\Model\Source\Status</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                    <item name="label" xsi:type="string" translate="true">Status</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="sortOrder" xsi:type="number">30</item>
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                </item>
            </argument>
        </column> -->
        <actionsColumn name="actions" class="Chirag\Events\Ui\Component\Listing\Column\EventsActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">entity_id</item>
                    <item name="urlEntityParamName" xsi:type="string">id</item>
                </item>
            </argument>
        </actionsColumn>
    </columns>
</listing>

Chirag->Events->Ui->Component->Listing-> Column->EventsActions.php

<?php
/**
 * @category   Chirag
 * @package    Chirag_Events
 * @author     chirag@czargroup.net
 * @copyright  This file was generated by using Module Creator provided by <developer@czargroup.net>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Chirag\Events\Ui\Component\Listing\Column;

class EventsActions extends \Magento\Ui\Component\Listing\Columns\Column
{
    const URL_PATH_EDIT = 'chirag_events/items/edit';

    /**
     * URL builder
     *
     * @var \Magento\Framework\UrlInterface
     */
    protected $_urlBuilder;

    /**
     * constructor
     *
     * @param \Magento\Framework\UrlInterface $urlBuilder
     * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
     * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory
     * @param array $components
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\UrlInterface $urlBuilder,
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
        array $components = [],
        array $data = []
    )
    {
        $this->_urlBuilder = $urlBuilder;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }


    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                $item[$this->getData('name')] = [
                    'edit' => [
                        'href' => $this->_urlBuilder->getUrl(
                            static::URL_PATH_EDIT,
                            [
                                'id' => $item['entity_id']
                            ]
                        ),
                        'label' => __('Edit')
                    ],
                ];
            }
        }
        return $dataSource;
    }
}

********************************************
Thats all....

Now some images for its look.