nystudio107 / generator-craftplugin

generator-craftplugin is a Yeoman generator for Craft CMS plugins
MIT License
74 stars 30 forks source link

I was expecting the CP page to work by default #69

Open echantigny opened 5 years ago

echantigny commented 5 years ago

After installing my base plugin, I was expecting to be able to click the CP section and it would just work. Unfortunately, I was given an error: Template not found: commerce-wishlist.

I did not change the name of any files. The only thing I did prior to installing it is to set the table fields I wanted for my plugin, which worked.

clowerweb commented 4 years ago

The plugin generator doesn't register any of this correctly. I spent all day debugging my way through it and finally got it.

  1. In your main plugin class, look for the Event::on with Plugins::EVENT_REGISTER_CP_URL_RULES, and change the $event->rules['siteActionTrigger1'] to $event->rules['YOUR-PLUGIN-HANDLE'], where "YOUR-PLUGIN-HANDLE" is commerce-wishlist in this case.
  2. Set the value of that to ['template' => 'commerce-wishlist/commerce-wishlist'] (or commerce-wishlist/index if you didn't set a name for the CP section in the generator config).
  3. Now you'll get a different error because of some other misconfigurations in the generator. Go to templates/commerce-wishlist.twig (or index.twig if you didn't name the section in the generator), and comment out or remove {% do view.registerAssetBundle("fostercommerce\\inventory\\assetbundles\\inventory\\InventoryAsset") %} on or around line 19. The file doesn't exist and will cause an error.
  4. Now you'll notice that the CP section loads, but the submit button doesn't appear in the page header (assuming you'll need it). That's because on or around line 35, extraPageHeaderHtml isn't a variable in the actual _layouts/cp template that this one extends. Change it to {% block actionButton %}, and then the following {% endset %} to {% endblock %} of course.

Hope this helps!