spicywebau / craft-content-templates

A Craft CMS plugin for providing content editors a starting point when creating entries
Other
4 stars 2 forks source link

Enable creating entries from template on all sites, not just the default #7

Closed IrateGod closed 8 months ago

IrateGod commented 8 months ago

Recently I stumbled across an issue with the Craft Content Templates plugin, where upon trying to apply a content template to a new entry, the process would fail with an unknown error and leave duplicated template entries in the Content Templates tab. Quickly I stumbled upon the issue on line 243 of the CpController: when creating a new entry on any site that isn't the current site (as specified in getElementById), the $element variable would end up being null, thus causing a Null Pointer Exception.

This Pull Request amends the functionality of the apply action by explicitly looking up the 'site' query parameter as it will be properly set by the Craft admin panel when creating a new entry, and adds an extra check to the $element variable in case it is still null.

Please feel free to suggest any required changes needed.

ttempleton commented 8 months ago

Thanks!