Magento 2 + create widget via installData Script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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







up vote
1
down vote

favorite
1












I need to custom requirement for creating a widget via Script. but I have facing an error when try to add a widget via below script



<?php

namespace TestXyzSetup;

use MagentoFrameworkSetup;

class InstallData implements SetupInstallDataInterface

/**
* @var SetupSampleDataExecutor
*/
protected $executor;
/**
* @var Installer
*/
protected $installer;

private $widgetFactory;

public function __construct(
SetupSampleDataExecutor $executor,
Installer $installer,
MagentoWidgetModelWidgetInstanceFactory $widgetFactory
)
$this->executor = $executor;
$this->installer = $installer;
$this->widgetFactory = $widgetFactory;


public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

$this->executor->exec($this->installer);

$instaFeedWidget = [
'instance_type' => 'TestXyzBlockWidgetInstagram',
'theme_id' => 2,
'title' => 'Instagram',
'store_ids' => '0',
'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
'sort_order' => 0,
'page_groups' => [[
'page_group' => 'pages',
'all_pages' => [
'page_id' => null,
//'group' => 'all_pages',
'layout_handle' => 'cms_index_index',
'block' => 'page.bottom',
'for' => 'all',
'template' => ''
]
]]
];
$this->widgetFactory->create()->setData($instaFeedWidget)->save();




But I am facing error TestXyzSetupInstaller does not exist



Any ideas will be welcomed.







share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    I need to custom requirement for creating a widget via Script. but I have facing an error when try to add a widget via below script



    <?php

    namespace TestXyzSetup;

    use MagentoFrameworkSetup;

    class InstallData implements SetupInstallDataInterface

    /**
    * @var SetupSampleDataExecutor
    */
    protected $executor;
    /**
    * @var Installer
    */
    protected $installer;

    private $widgetFactory;

    public function __construct(
    SetupSampleDataExecutor $executor,
    Installer $installer,
    MagentoWidgetModelWidgetInstanceFactory $widgetFactory
    )
    $this->executor = $executor;
    $this->installer = $installer;
    $this->widgetFactory = $widgetFactory;


    public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

    $this->executor->exec($this->installer);

    $instaFeedWidget = [
    'instance_type' => 'TestXyzBlockWidgetInstagram',
    'theme_id' => 2,
    'title' => 'Instagram',
    'store_ids' => '0',
    'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
    'sort_order' => 0,
    'page_groups' => [[
    'page_group' => 'pages',
    'all_pages' => [
    'page_id' => null,
    //'group' => 'all_pages',
    'layout_handle' => 'cms_index_index',
    'block' => 'page.bottom',
    'for' => 'all',
    'template' => ''
    ]
    ]]
    ];
    $this->widgetFactory->create()->setData($instaFeedWidget)->save();




    But I am facing error TestXyzSetupInstaller does not exist



    Any ideas will be welcomed.







    share|improve this question






















      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I need to custom requirement for creating a widget via Script. but I have facing an error when try to add a widget via below script



      <?php

      namespace TestXyzSetup;

      use MagentoFrameworkSetup;

      class InstallData implements SetupInstallDataInterface

      /**
      * @var SetupSampleDataExecutor
      */
      protected $executor;
      /**
      * @var Installer
      */
      protected $installer;

      private $widgetFactory;

      public function __construct(
      SetupSampleDataExecutor $executor,
      Installer $installer,
      MagentoWidgetModelWidgetInstanceFactory $widgetFactory
      )
      $this->executor = $executor;
      $this->installer = $installer;
      $this->widgetFactory = $widgetFactory;


      public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

      $this->executor->exec($this->installer);

      $instaFeedWidget = [
      'instance_type' => 'TestXyzBlockWidgetInstagram',
      'theme_id' => 2,
      'title' => 'Instagram',
      'store_ids' => '0',
      'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
      'sort_order' => 0,
      'page_groups' => [[
      'page_group' => 'pages',
      'all_pages' => [
      'page_id' => null,
      //'group' => 'all_pages',
      'layout_handle' => 'cms_index_index',
      'block' => 'page.bottom',
      'for' => 'all',
      'template' => ''
      ]
      ]]
      ];
      $this->widgetFactory->create()->setData($instaFeedWidget)->save();




      But I am facing error TestXyzSetupInstaller does not exist



      Any ideas will be welcomed.







      share|improve this question












      I need to custom requirement for creating a widget via Script. but I have facing an error when try to add a widget via below script



      <?php

      namespace TestXyzSetup;

      use MagentoFrameworkSetup;

      class InstallData implements SetupInstallDataInterface

      /**
      * @var SetupSampleDataExecutor
      */
      protected $executor;
      /**
      * @var Installer
      */
      protected $installer;

      private $widgetFactory;

      public function __construct(
      SetupSampleDataExecutor $executor,
      Installer $installer,
      MagentoWidgetModelWidgetInstanceFactory $widgetFactory
      )
      $this->executor = $executor;
      $this->installer = $installer;
      $this->widgetFactory = $widgetFactory;


      public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

      $this->executor->exec($this->installer);

      $instaFeedWidget = [
      'instance_type' => 'TestXyzBlockWidgetInstagram',
      'theme_id' => 2,
      'title' => 'Instagram',
      'store_ids' => '0',
      'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
      'sort_order' => 0,
      'page_groups' => [[
      'page_group' => 'pages',
      'all_pages' => [
      'page_id' => null,
      //'group' => 'all_pages',
      'layout_handle' => 'cms_index_index',
      'block' => 'page.bottom',
      'for' => 'all',
      'template' => ''
      ]
      ]]
      ];
      $this->widgetFactory->create()->setData($instaFeedWidget)->save();




      But I am facing error TestXyzSetupInstaller does not exist



      Any ideas will be welcomed.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 at 11:38









      Yogesh

      866822




      866822




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Try with this:



          <?php

          namespace TestXyzSetup;

          use MagentoFrameworkSetup;

          class InstallData implements SetupInstallDataInterface

          /**
          * @var SetupSampleDataExecutor
          */
          protected $executor;


          private $widgetFactory;

          public function __construct(
          SetupSampleDataExecutor $executor,
          MagentoWidgetModelWidgetInstanceFactory $widgetFactory
          )
          $this->executor = $executor;
          $this->widgetFactory = $widgetFactory;


          public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

          $instaFeedWidget = [
          'instance_type' => 'TestXyzBlockWidgetInstagram',
          'theme_id' => 2,
          'title' => 'Instagram',
          'store_ids' => '0',
          'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
          'sort_order' => 0,
          'page_groups' => [[
          'page_group' => 'pages',
          'all_pages' => [
          'page_id' => null,
          //'group' => 'all_pages',
          'layout_handle' => 'cms_index_index',
          'block' => 'page.bottom',
          'for' => 'all',
          'template' => ''
          ]
          ]]
          ];
          $this->widgetFactory->create()->setData($instaFeedWidget)->save();




          I have removed Installer $installer, and $this->installer = $installer; also variable



          /**
          * @var Installer
          */
          protected $installer;





          share|improve this answer




















          • Okay let me check
            – Yogesh
            Aug 23 at 11:56










          • One supplementary question, Layout settings are not able saved, Have you any idea ?
            – Yogesh
            Aug 23 at 12:24

















          up vote
          1
          down vote













          The reason to the error is Installer argument in construct function. It needs to be connected with some class like how $widgetFactory is done. After that clear code from generated/code and run.






          share|improve this answer




















          • Let me chek that
            – Yogesh
            Aug 23 at 11:56










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f239348%2fmagento-2-create-widget-via-installdata-script%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          Try with this:



          <?php

          namespace TestXyzSetup;

          use MagentoFrameworkSetup;

          class InstallData implements SetupInstallDataInterface

          /**
          * @var SetupSampleDataExecutor
          */
          protected $executor;


          private $widgetFactory;

          public function __construct(
          SetupSampleDataExecutor $executor,
          MagentoWidgetModelWidgetInstanceFactory $widgetFactory
          )
          $this->executor = $executor;
          $this->widgetFactory = $widgetFactory;


          public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

          $instaFeedWidget = [
          'instance_type' => 'TestXyzBlockWidgetInstagram',
          'theme_id' => 2,
          'title' => 'Instagram',
          'store_ids' => '0',
          'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
          'sort_order' => 0,
          'page_groups' => [[
          'page_group' => 'pages',
          'all_pages' => [
          'page_id' => null,
          //'group' => 'all_pages',
          'layout_handle' => 'cms_index_index',
          'block' => 'page.bottom',
          'for' => 'all',
          'template' => ''
          ]
          ]]
          ];
          $this->widgetFactory->create()->setData($instaFeedWidget)->save();




          I have removed Installer $installer, and $this->installer = $installer; also variable



          /**
          * @var Installer
          */
          protected $installer;





          share|improve this answer




















          • Okay let me check
            – Yogesh
            Aug 23 at 11:56










          • One supplementary question, Layout settings are not able saved, Have you any idea ?
            – Yogesh
            Aug 23 at 12:24














          up vote
          2
          down vote



          accepted










          Try with this:



          <?php

          namespace TestXyzSetup;

          use MagentoFrameworkSetup;

          class InstallData implements SetupInstallDataInterface

          /**
          * @var SetupSampleDataExecutor
          */
          protected $executor;


          private $widgetFactory;

          public function __construct(
          SetupSampleDataExecutor $executor,
          MagentoWidgetModelWidgetInstanceFactory $widgetFactory
          )
          $this->executor = $executor;
          $this->widgetFactory = $widgetFactory;


          public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

          $instaFeedWidget = [
          'instance_type' => 'TestXyzBlockWidgetInstagram',
          'theme_id' => 2,
          'title' => 'Instagram',
          'store_ids' => '0',
          'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
          'sort_order' => 0,
          'page_groups' => [[
          'page_group' => 'pages',
          'all_pages' => [
          'page_id' => null,
          //'group' => 'all_pages',
          'layout_handle' => 'cms_index_index',
          'block' => 'page.bottom',
          'for' => 'all',
          'template' => ''
          ]
          ]]
          ];
          $this->widgetFactory->create()->setData($instaFeedWidget)->save();




          I have removed Installer $installer, and $this->installer = $installer; also variable



          /**
          * @var Installer
          */
          protected $installer;





          share|improve this answer




















          • Okay let me check
            – Yogesh
            Aug 23 at 11:56










          • One supplementary question, Layout settings are not able saved, Have you any idea ?
            – Yogesh
            Aug 23 at 12:24












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Try with this:



          <?php

          namespace TestXyzSetup;

          use MagentoFrameworkSetup;

          class InstallData implements SetupInstallDataInterface

          /**
          * @var SetupSampleDataExecutor
          */
          protected $executor;


          private $widgetFactory;

          public function __construct(
          SetupSampleDataExecutor $executor,
          MagentoWidgetModelWidgetInstanceFactory $widgetFactory
          )
          $this->executor = $executor;
          $this->widgetFactory = $widgetFactory;


          public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

          $instaFeedWidget = [
          'instance_type' => 'TestXyzBlockWidgetInstagram',
          'theme_id' => 2,
          'title' => 'Instagram',
          'store_ids' => '0',
          'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
          'sort_order' => 0,
          'page_groups' => [[
          'page_group' => 'pages',
          'all_pages' => [
          'page_id' => null,
          //'group' => 'all_pages',
          'layout_handle' => 'cms_index_index',
          'block' => 'page.bottom',
          'for' => 'all',
          'template' => ''
          ]
          ]]
          ];
          $this->widgetFactory->create()->setData($instaFeedWidget)->save();




          I have removed Installer $installer, and $this->installer = $installer; also variable



          /**
          * @var Installer
          */
          protected $installer;





          share|improve this answer












          Try with this:



          <?php

          namespace TestXyzSetup;

          use MagentoFrameworkSetup;

          class InstallData implements SetupInstallDataInterface

          /**
          * @var SetupSampleDataExecutor
          */
          protected $executor;


          private $widgetFactory;

          public function __construct(
          SetupSampleDataExecutor $executor,
          MagentoWidgetModelWidgetInstanceFactory $widgetFactory
          )
          $this->executor = $executor;
          $this->widgetFactory = $widgetFactory;


          public function install(SetupModuleDataSetupInterface $setup, SetupModuleContextInterface $moduleContext)

          $instaFeedWidget = [
          'instance_type' => 'TestXyzBlockWidgetInstagram',
          'theme_id' => 2,
          'title' => 'Instagram',
          'store_ids' => '0',
          'widget_parameters' => '"title":"Instagram ","numberimage":"16","resolution":"standard_resolution"',
          'sort_order' => 0,
          'page_groups' => [[
          'page_group' => 'pages',
          'all_pages' => [
          'page_id' => null,
          //'group' => 'all_pages',
          'layout_handle' => 'cms_index_index',
          'block' => 'page.bottom',
          'for' => 'all',
          'template' => ''
          ]
          ]]
          ];
          $this->widgetFactory->create()->setData($instaFeedWidget)->save();




          I have removed Installer $installer, and $this->installer = $installer; also variable



          /**
          * @var Installer
          */
          protected $installer;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 23 at 11:49









          kunj

          2,3772420




          2,3772420











          • Okay let me check
            – Yogesh
            Aug 23 at 11:56










          • One supplementary question, Layout settings are not able saved, Have you any idea ?
            – Yogesh
            Aug 23 at 12:24
















          • Okay let me check
            – Yogesh
            Aug 23 at 11:56










          • One supplementary question, Layout settings are not able saved, Have you any idea ?
            – Yogesh
            Aug 23 at 12:24















          Okay let me check
          – Yogesh
          Aug 23 at 11:56




          Okay let me check
          – Yogesh
          Aug 23 at 11:56












          One supplementary question, Layout settings are not able saved, Have you any idea ?
          – Yogesh
          Aug 23 at 12:24




          One supplementary question, Layout settings are not able saved, Have you any idea ?
          – Yogesh
          Aug 23 at 12:24












          up vote
          1
          down vote













          The reason to the error is Installer argument in construct function. It needs to be connected with some class like how $widgetFactory is done. After that clear code from generated/code and run.






          share|improve this answer




















          • Let me chek that
            – Yogesh
            Aug 23 at 11:56














          up vote
          1
          down vote













          The reason to the error is Installer argument in construct function. It needs to be connected with some class like how $widgetFactory is done. After that clear code from generated/code and run.






          share|improve this answer




















          • Let me chek that
            – Yogesh
            Aug 23 at 11:56












          up vote
          1
          down vote










          up vote
          1
          down vote









          The reason to the error is Installer argument in construct function. It needs to be connected with some class like how $widgetFactory is done. After that clear code from generated/code and run.






          share|improve this answer












          The reason to the error is Installer argument in construct function. It needs to be connected with some class like how $widgetFactory is done. After that clear code from generated/code and run.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 23 at 11:49









          LAW

          623516




          623516











          • Let me chek that
            – Yogesh
            Aug 23 at 11:56
















          • Let me chek that
            – Yogesh
            Aug 23 at 11:56















          Let me chek that
          – Yogesh
          Aug 23 at 11:56




          Let me chek that
          – Yogesh
          Aug 23 at 11:56

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f239348%2fmagento-2-create-widget-via-installdata-script%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery