function commerce_shipping_entity_operation in Commerce Shipping 8.2
Implements hook_entity_operation().
File
- ./
commerce_shipping.module, line 276 - Provides core shipping functionality.
Code
function commerce_shipping_entity_operation(EntityInterface $entity) {
// Only show the "Shipments" operation link for commerce_order entities.
if ($entity
->getEntityTypeId() !== 'commerce_order') {
return;
}
// Do not show for a "cart" order.
if ($entity
->hasField('cart') && $entity
->get('cart')->value) {
return;
}
// Only show if the user can create shipments.
if (!$entity
->access('create')) {
return;
}
$operations = [];
$operations['shipments'] = [
'title' => t('Shipments'),
'url' => Url::fromRoute('entity.commerce_shipment.collection', [
'commerce_order' => $entity
->id(),
]),
'weight' => 60,
];
return $operations;
}