/**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $id = strtolower(trim($form_state->getValue('id')));
     if (strpos($id, ' ') !== FALSE || $id == 'all') {
         $form_state->setErrorByName('id', $this->t('You have entered an invalid status ID.'));
     }
     if (OrderStatus::load($id)) {
         $form_state->setErrorByName('id', $this->t('This ID is already in use.  Please specify a unique ID.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('uc_order.settings');
     foreach ($form_state->getValue('order_states') as $key => $value) {
         $config->set("default_state.{$key}", $value['default']);
     }
     $config->save();
     foreach ($form_state->getValue('order_statuses') as $id => $value) {
         $status = OrderStatus::load($id);
         if (!empty($value['remove'])) {
             $status->delete();
             drupal_set_message(t('Order status %status removed.', ['%status' => $status->getName()]));
         } else {
             $status->setName($value['name']);
             $status->setWeight((int) $value['weight']);
             // The state cannot be changed if the status is locked.
             if (!$status->isLocked()) {
                 $status->setState($value['state']);
             }
             $status->save();
         }
     }
     parent::submitForm($form, $form_state);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $status = OrderStatus::load($this->getValue($values));
     return $this->sanitizeValue($status->getName());
 }