You are here

public function ShippingMethodListBuilder::submitForm in Commerce Shipping 8.2

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/ShippingMethodListBuilder.php, line 205

Class

ShippingMethodListBuilder
Defines the list builder for shipping methods.

Namespace

Drupal\commerce_shipping

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue($this->entitiesKey) as $id => $value) {
    if (isset($this->entities[$id]) && $this->entities[$id]
      ->getWeight() != $value['weight']) {

      // Save entity only when its weight was changed.
      $this->entities[$id]
        ->setWeight($value['weight']);
      $this->entities[$id]
        ->save();
    }
  }
}