I would like to add a button to the edit entry screen, only for already saved entries, alongside the "Share" button.
When clicked, I'd like to call my plugin's controller action and post the entry ID.
Where would I look to see how to do this?
Not sure if you can put it next to the Share button, but check out the Triggers feature of Button Box...
You can create a "Triggers" field, which is just a button that hooks up to JS. Then use the JS to ping your Controller via AJAX.
The button exists as a field, so you could just put that field at the top of your field layout. It's not well documented, but it's really easy to do.
I learned in this ticket that you can do this with Craft::$app->getView()->hook()
in your plugin's init()
method. It won't put the button in the top near the "Share" button but rather in the sidebar under the settings. Here's an example (you'll want to customize it to your liking):
Craft::$app->getView()->hook('cp.entries.edit.details', function(array &$context) {
$entry = $context['entry'];
if ((int)$entry->sectionId === YOUR_SECTION_ID_HERE) {
$url = '/your/controller/action/url/';
return '<div class="meta"><a href="' . $url . '" class="btn">My Button</a></div>';
}
});