Answers.Body: <p>Not sure if you can put it next to the Share button, but check out the <strong>Triggers</strong> feature of Button Box...</p>
  
  <blockquote>
    <p><a href="https://github.com/supercool/buttonbox" rel="nofollow noreferrer">https://github.com/supercool/buttonbox</a></p>
  </blockquote>
  
  <p>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.</p>
  
  <p>The button exists as a <em>field</em>, 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-11T01:00:18.027Z
Answers.Text: Thanks for the reply! I need this to be more tightly integrated via my plugin, though. It's a workflow thing. And I need to link to another CP screen, passing along the entry ID.
Answers.UserDisplayName: Mark J. Reeves
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-11T00:40:55.213Z
Answers.LastActivityDate: 2018-06-11T00:40:55.213Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>I learned in <a href="https://craftcms.stackexchange.com/questions/14516/how-to-add-a-custom-button-at-the-right-section-of-an-entry">this ticket</a> that you can do this with <code>Craft::$app-&gt;getView()-&gt;hook()</code> in your plugin's <code>init()</code> 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):</p>
  
  <pre><code>Craft::$app-&gt;getView()-&gt;hook('cp.entries.edit.details', function(array &amp;$context) {
  
      $entry = $context['entry'];
  
      if ((int)$entry-&gt;sectionId === YOUR_SECTION_ID_HERE) {
  
          $url = '/your/controller/action/url/';
  
          return '&lt;div class="meta"&gt;&lt;a href="' . $url . '" class="btn"&gt;My Button&lt;/a&gt;&lt;/div&gt;';
      }
  
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-20T19:21:47.177Z
Answers.LastActivityDate: 2019-01-20T19:21:47.177Z
Answers.UserDisplayName: Ryan
Body: <p>I would like to add a button to the edit entry screen, only for already saved entries, alongside the "Share" button.</p>
  
  <p>When clicked, I'd like to call my plugin's controller action and post the entry ID.</p>
  
  <p>Where would I look to see how to do this?</p>
  
Tags: <plugin-development><plugins><control-panel><controller><editing>
Title: Add a button to the entry edit screen via plugin
ThreadText: # Add a button to the entry edit screen via plugin
  
  (Asked by: username_0 on 2018-06-11)
  
  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?
  
  **Tags:** plugin-development, plugins, control-panel, controller, editing
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-06-11. Score: 1
  
  Not sure if you can put it next to the Share button, but check out the **Triggers** feature of Button Box...
  
  > <https://github.com/supercool/buttonbox>
  
  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.
  
  > **Comments:**
  > **username_0**: Thanks for the reply! I need this to be more tightly integrated via my plugin, though. It's a workflow thing. And I need to link to another CP screen, passing along the entry ID.  
  
  ---
  
  ### Answer by username_2 on 2019-01-20. Score: 1
  
  I learned in [this ticket](https://craftcms.stackexchange.com/questions/14516/how-to-add-a-custom-button-at-the-right-section-of-an-entry) 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>';
      }
  
  });
  
  ```
  
  
  ---
  
  