OrderUnlockForm.php in Commerce Core 8.2
File
modules/order/src/Form/OrderUnlockForm.php
View source
<?php
namespace Drupal\commerce_order\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class OrderUnlockForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to unlock the order %label?', [
'%label' => $this->entity
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Unlock');
}
public function getCancelUrl() {
return $this->entity
->toUrl('collection');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$order = $this->entity;
$order
->unlock();
$order
->save();
$this
->messenger()
->addMessage($this
->t('The order %label has been unlocked.', [
'%label' => $order
->label(),
]));
$form_state
->setRedirectUrl($order
->toUrl('collection'));
}
}