How do I a custom entity operation with a webform submission? My lack of D8 experience is going to show by just how many unknowns I have here. I hope someone can link some of the pieces for me.

I created a custom action using hook_entity_operation_alter() on the admin/structure/webform/manage/dis_document_generator/results/submissions page as you can see below. I'm guessing this will show up on various other pages to which is fine.

Currently as you can see the url is set to the current page but this needs to change once I have a controller redirect to. Also, it would be nice to add this operation through a controller instead of a hook but that's not important at the moment.

    /**
     * Implements hook_entity_operation_alter()
     */
    function dis_doc_gen_entity_operation_alter(array &amp;$operations, \Drupal\Core\Entity\EntityInterface $entity) {
      if ($entity-&gt;getEntityTypeId() === 'webform_submission' &amp;&amp; $entity-&gt;bundle() === 'dis_document_generator') {

        static $operation;
        static $permission;

        if (is_null($operation)) {
          $user = \Drupal::currentUser();
          $permission = $user-&gt;hasPermission('utilize mq client');

          $url = \Drupal\Core\Url::fromRoute('&lt;current&gt;');

          $operation = [
            'title' =&gt; t('Send XML'),
            'weight' =&gt; 8,
            'url' =&gt; $url,
          ];
        }

        if ($permission) {
          $operations['send_xml'] = $operation;
        }
      }
    }


I was using WebformSubmissionNotesForm.php as a sample to create a controller because it looked relatively simple but I'm not sure if it's a best choice because I don't actually need a form. I'm just going to perform an action and then return however using it for now.

The router for it is this:

entity.webform_submission.notes_form:
  path: '/admin/structure/webform/manage/{webform}/submission/{webform_submission}/notes'
  defaults:
    _entity_form: 'webform_submission.notes'
    _title_callback: '\Drupal\webform\Controller\WebformSubmissionViewController::title'
  requirements:
    _entity_access: 'webform_submission.notes'


With my module being called dis_doc_gen I gather that my router details should look like this?:

dis_doc_gen.webform_submission.sendxml:
  path: '/admin/structure/webform/manage/{webform}/submission/{webform_submission}/sendxml'
  defaults:
    _entity_form: 'dis_doc_gen.sendxml'
    _title_callback: 'Send XML'
  requirements:
    _entity_access: 'dis_doc_gen.utilize_mq_client'


where my permission is called utilize mq client and so I believe it would be represented here as dis_doc_gen.utilize_mq_client.

Finally, WebformSubmissionNotesForm.php sits under webform/src. The one plugin I managed to do for my webform had to go under webform/src/Plugin/WebformHandler so I'm wondering since this is off a webform submission whether I need to place a controller at:


webform/src or
webform/src/Plugin/WebformHandler or
webform/src/Plugin/WebformSubmissionHandler.


Last, webform defines WebformSubmissionNotesForm in it's header like this:

&lt;?php
/**
 * Defines the WebformSubmission entity.
 *
 * @ingroup webform
 *
 * @ContentEntityType(
 *   handlers = {
 *     "form" = {
 *       "notes" = "Drupal\webform\WebformSubmissionNotesForm",


Since I can't have that hardcoded like that for my new controller I gather that's fine because I can just attach my controller through the interface.
It seems the answer came from spending a day (and a bit) just studying the inner workings of D8 and realizing just how much is done for you that wasn't the case in D7.

Ultimately I want to send the action to a Controller, not a plugin and the primary source for getting enough grounding to figure it out came from the following:


https://www.drupal.org/docs/8/api/routing-system/structure-of-routes
https://www.drupal.org/docs/8/api/configuration-api/creating-a-configuration-entity-type-in-drupal-8
https://www.drupal.org/docs/8/api/entity-api/creating-a-content-entity-type-in-drupal-8