I am not sure there is not a simpler way. But this way you'll get what you want.
a) Create a custom field to implement your logic. You can extend from any basic custom field types.
b) Simply set it manually to default to 0 (the attribute default="0"
is accepted in most form types). This will not set the value until the user actually saves the preferences; or you could preset the values in the script mentioned below.
c) Yes. it works for any extension type. Check the docs here.
Please take a moment to check the naming convention: the class name in the installer must be exact, otherwise it will simply not be invoked, and no error will be thrown to set you on the right path. In your install.php
methods i.e. install, update, preflight, postflight
, you can queue messages:
JFactory::getApplication()->enqueueMessage()
to know when code is working.
For example
If my extension plugin xml name is "easyhttps":
<filename plugin="easyhttps">easyhttps.php</filename>
becomes PlgSystemJsonloggerInstallerScript in the classname of the installer:
class PlgSystemJsonloggerInstallerScript
A plugin with an underscore in its name: "stripe_button"
<filename plugin="stripe_button">stripe_button.php</filename>
Will keep it in the classname of the installer: PlgSystemStripe_buttonInstallerScript
class PlgSystemStripe_buttonInstallerScript
Bonus: A plugin with an underscore and a dash in its name: "editors-xtd/stripe_xtd"
<extension version="2.5.0" type="plugin" group="editors-xtd" method="upgrade">
<filename plugin="stripe_xtd">stripe_xtd.php</filename>
Will lose the dash in the classname of the installer: Plgeditorsxtdstripe_xtdInstallerScript
class Plgeditorsxtdstripe_xtdInstallerScript
Capitalisation
It is not too important: all the following work:
class PlgEditorsxtdstripe_xtdInstallerScript
class PlgEditorsxtdStripe_xtdInstallerScript
class Plgeditorsxtdstripe_xtdInstallerScript