I am trying to create a custom action to do bulk operations on Commerce Orders.
I have a file at: mymodule/src/Plugin/Action/DeleteOrderAndApps.php:
namespace DrupalmymodulePluginAction; use Drupalcommerce_orderEntityOrder; use DrupalCoreActionActionBase; use DrupalCoreSessionAccountInterface; use DrupalnodeEntityNode; /** * 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) { some code here } /** * {@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 file: mymodule/config/install/system.action.delete_order_and_apps.yml
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).
This is Core 8.9.20 and Commerce 8.x-2.24.