/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $status = $this->entity->save(); drupal_set_message($this->t('The product type %label has been successfully saved.', ['%label' => $this->entity->label()])); $form_state->setRedirect('entity.commerce_product_type.collection'); if ($status == SAVED_NEW) { commerce_product_add_stores_field($this->entity); commerce_product_add_body_field($this->entity); commerce_product_add_variations_field($this->entity); } }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $status = $this->entity->save(); // Update the default value of the status field. $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $this->entity->id()]); $value = (bool) $form_state->getValue('product_status'); if ($product->status->value != $value) { $fields = $this->entityFieldManager->getFieldDefinitions('commerce_product', $this->entity->id()); $fields['status']->getConfig($this->entity->id())->setDefaultValue($value)->save(); $this->entityFieldManager->clearCachedFieldDefinitions(); } drupal_set_message($this->t('The product type %label has been successfully saved.', ['%label' => $this->entity->label()])); $form_state->setRedirect('entity.commerce_product_type.collection'); if ($status == SAVED_NEW) { commerce_product_add_stores_field($this->entity); commerce_product_add_body_field($this->entity); commerce_product_add_variations_field($this->entity); } }