class OrderReassignForm in Commerce Core 8.2
Provides a form for assigning orders to a different customer.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\commerce_order\Form\OrderReassignForm uses CustomerFormTrait
Expanded class hierarchy of OrderReassignForm
1 string reference to 'OrderReassignForm'
- commerce_order.routing.yml in modules/
order/ commerce_order.routing.yml - modules/order/commerce_order.routing.yml
File
- modules/
order/ src/ Form/ OrderReassignForm.php, line 15
Namespace
Drupal\commerce_order\FormView source
class OrderReassignForm extends FormBase {
use CustomerFormTrait;
/**
* The current order.
*
* @var \Drupal\commerce_order\Entity\OrderInterface
*/
protected $order;
/**
* The order assignment service.
*
* @var \Drupal\commerce_order\OrderAssignmentInterface
*/
protected $orderAssignment;
/**
* The user storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $userStorage;
/**
* Constructs a new OrderReassignForm object.
*
* @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match
* The current route match.
* @param \Drupal\commerce_order\OrderAssignmentInterface $order_assignment
* The order assignment service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(CurrentRouteMatch $current_route_match, OrderAssignmentInterface $order_assignment, EntityTypeManagerInterface $entity_type_manager) {
$this->order = $current_route_match
->getParameter('commerce_order');
$this->orderAssignment = $order_assignment;
$this->userStorage = $entity_type_manager
->getStorage('user');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_route_match'), $container
->get('commerce_order.order_assignment'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'commerce_order_reassign_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$customer = $this->order
->getCustomer();
if ($customer
->isAnonymous()) {
$current_customer = $this
->t('anonymous user with the email %email', [
'%email' => $this->order
->getEmail(),
]);
}
else {
// If the display name has been altered to not be the email address,
// show the email as well.
if ($customer
->getDisplayName() != $customer
->getEmail()) {
$customer_link_text = $this
->t('@display (@email)', [
'@display' => $customer
->getDisplayName(),
'@email' => $customer
->getEmail(),
]);
}
else {
$customer_link_text = $customer
->getDisplayName();
}
$current_customer = $this->order
->getCustomer()
->toLink($customer_link_text)
->toString();
}
$form['current_customer'] = [
'#type' => 'item',
'#markup' => $this
->t('The order is currently assigned to @customer.', [
'@customer' => $current_customer,
]),
];
$form += $this
->buildCustomerForm($form, $form_state, $this->order);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Reassign order'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->submitCustomerForm($form, $form_state);
$values = $form_state
->getValues();
/** @var \Drupal\user\UserInterface $user */
$user = $this->userStorage
->load($values['uid']);
$this->orderAssignment
->assign($this->order, $user);
$this
->messenger()
->addMessage($this
->t('The order %label has been assigned to customer %customer.', [
'%label' => $this->order
->label(),
'%customer' => $this->order
->getCustomer()
->label(),
]));
$form_state
->setRedirectUrl($this->order
->toUrl('collection'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CustomerFormTrait:: |
public | function | Builds the customer form. | |
CustomerFormTrait:: |
public | function | Ajax callback. | |
CustomerFormTrait:: |
public | function | Submit handler for the customer select form. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
OrderReassignForm:: |
protected | property | The current order. | |
OrderReassignForm:: |
protected | property | The order assignment service. | |
OrderReassignForm:: |
protected | property | The user storage. | |
OrderReassignForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
OrderReassignForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
OrderReassignForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
OrderReassignForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
OrderReassignForm:: |
public | function | Constructs a new OrderReassignForm object. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |