How to install a SiteKey from a Package

Permalink 1 user found helpful
V8.3.2
Not a cry for help, actually some info on how I achieved it so others may hopefully find out how more easily than I did. As usual the paucity of C5 documentation made it like sticking needles in my eyes so enough of that, here's how I did it.

In your package controller's installer:
$key = SiteKey::getByHandle('site_baseurl'); // check key handle doesn't exist
        if($key === null) {
            $key = SiteKey::add('text', [ 'akName' => 'Site base URL', 'akHandle' => 'site_baseurl' ], $pkg);
        }


It was eventually finding out that SiteKey was the actually term I needed to search for that got me the information. All C5 docs seem to cover only UserKey, and 'Custom Attribute' as it's called in the Dash obviously got me nowhere.

This will uninstall the key(s) with your package as expected, too.

surefyre
 
mnakalay replied on at Permalink Reply
mnakalay
Thank you, that's the kind of hard-to-find tidbits that are always great to have handy.
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi surefyre,

When you discover how to do things not covered in the documentation and tutorials, please add/update the documentation or contribute a tutorial.
https://documentation.concrete5.org/contribute...