I am trying to create a custom action for bulk operations on commerce orders.
I am using the following code.
mymodule/src/Plugin/Action/DeleteOrderAndApps.php
namespace Drupal\mymodule\Plugin\Action;
use Drupal\commerce_order\Entity\Order;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\Entity\Node;
/**
* Delete Order and attached Apps action
*
* @Action(
* id = "delete_order_and_apps",
* label = @Translation("Delete Order and Apps"),
* type = "commerce_order"
* )
*/
class DeleteOrderAndApps extends ActionBase {
/**
* {@inheritdoc}
*
*/
public function execute(Order $order = NULL) {
// …
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = $object->access('delete', $account, TRUE);
return $return_as_object ? $result : $result->isAllowed();
}
}
I am not sure I need it, but I also have the mymodule/config/install/system.action.delete_order_and_apps.yml file.
langcode: en
status: true
dependencies:
module:
- commerce_order
id: delete_order_and_apps
label: 'Delete Order and Apps'
type: commerce_order
plugin: delete_order_and_apps
configuration: { }
The confusing part is there are 2 different bulk options: VBO and core's bulk actions for Order entity. Sadly these don't use the same action definitions but my new action does not show as an option for either of these when creating a view. I have done many of these the same way but all are Node actions.
Not sure if something missing in my code or possibly something missing in Commerce that is required to allow adding custom actions (something missing in entity definition perhaps).
I am using Drupal 8.9.20 and the Commerce module 8.x-2.24.