diff -u b/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php --- b/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -379,13 +379,15 @@ $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link); $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label()); - if ($status == SAVED_NEW) { - $this->logger('content')->notice('@type: added %title.', $context); - drupal_set_message(t('@type %title has been created.', $t_args)); - } - else { - $this->logger('content')->notice('@type: updated %title.', $context); - drupal_set_message(t('@type %title has been updated.', $t_args)); + switch ($status) { + case SAVED_NEW: + $this->logger('content')->notice('@type: added %title.', $context); + drupal_set_message(t('@type %title has been created.', $t_args)); + break; + case SAVED_UPDATED: + $this->logger('content')->notice('@type: updated %title.', $context); + drupal_set_message(t('@type %title has been updated.', $t_args)); + break; } if ($node->id()) { diff -u b/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php --- b/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -107,13 +107,9 @@ $form_state->set('user', $account); $form_state->setValue('uid', $account->id()); - if($status == SAVED_NEW) { + if($status != SAVED_UPDATED) { $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form'))); } - else { - $this->logger('user')->notice('Can not create New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form'))); - return $status; - } // Add plain text password into user account to generate mail tokens. $account->password = $pass; only in patch2: unchanged: --- a/core/modules/action/src/ActionFormBase.php +++ b/core/modules/action/src/ActionFormBase.php @@ -146,10 +146,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); + $status = $this->entity->save(); drupal_set_message($this->t('The action has been successfully saved.')); $form_state->setRedirect('entity.action.collection'); + return $status; } } only in patch2: unchanged: --- a/core/modules/aggregator/src/FeedForm.php +++ b/core/modules/aggregator/src/FeedForm.php @@ -21,16 +21,21 @@ class FeedForm extends ContentEntityForm { */ public function save(array $form, FormStateInterface $form_state) { $feed = $this->entity; - $insert = (bool) $feed->id(); - $feed->save(); - if ($insert) { - drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label()))); - $form_state->setRedirectUrl($feed->urlInfo('canonical')); - } - else { - $this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview')))); - drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label()))); + $status = $feed->save(); + + switch ($status) { + case SAVED_UPDATED: + drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label()))); + $form_state->setRedirectUrl($feed->urlInfo('canonical')); + break; + case SAVED_NEW: + $this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview')))); + drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label()))); + break; } + + return $status; } + } only in patch2: unchanged: --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -177,47 +177,42 @@ public function save(array $form, FormStateInterface $form_state) { $block->setNewRevision(); } - $insert = $block->isNew(); - $block->save(); + $status = $block->save(); $context = array('@type' => $block->bundle(), '%info' => $block->label()); $logger = $this->logger('block_content'); $block_type = $this->blockContentTypeStorage->load($block->bundle()); $t_args = array('@type' => $block_type->label(), '%info' => $block->label()); - if ($insert) { - $logger->notice('@type: added %info.', $context); - drupal_set_message($this->t('@type %info has been created.', $t_args)); - } - else { - $logger->notice('@type: updated %info.', $context); - drupal_set_message($this->t('@type %info has been updated.', $t_args)); + switch ($status) { + case SAVED_NEW: + $logger->notice('@type: added %info.', $context); + drupal_set_message($this->t('@type %info has been created.', $t_args)); + break; + case SAVED_UPDATED: + $logger->notice('@type: updated %info.', $context); + drupal_set_message($this->t('@type %info has been updated.', $t_args)); + break; } - if ($block->id()) { - $form_state->setValue('id', $block->id()); - $form_state->set('id', $block->id()); - if ($insert) { - if (!$theme = $block->getTheme()) { - $theme = $this->config('system.theme')->get('default'); - } - $form_state->setRedirect( - 'block.admin_add', - array( - 'plugin_id' => 'block_content:' . $block->uuid(), - 'theme' => $theme, - ) - ); - } - else { - $form_state->setRedirectUrl($block->urlInfo('collection')); + $form_state->setValue('id', $block->id()); + $form_state->set('id', $block->id()); + if ($status == SAVED_NEW) { + if (!$theme = $block->getTheme()) { + $theme = $this->config('system.theme')->get('default'); } + $form_state->setRedirect( + 'block.admin_add', + array( + 'plugin_id' => 'block_content:' . $block->uuid(), + 'theme' => $theme, + ) + ); } else { - // In the unlikely case something went wrong on save, the block will be - // rebuilt and block form redisplayed. - drupal_set_message($this->t('The block could not be saved.'), 'error'); - $form_state->setRebuild(); + $form_state->setRedirectUrl($block->urlInfo('collection')); } + + return $status; } /** only in patch2: unchanged: --- a/core/modules/block_content/src/BlockContentTypeForm.php +++ b/core/modules/block_content/src/BlockContentTypeForm.php @@ -98,17 +98,20 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->link($this->t('Edit')); $logger = $this->logger('block_content'); - if ($status == SAVED_UPDATED) { - drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); - $logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link)); - } - else { - block_content_add_body_field($block_type->id()); - drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label()))); - $logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link)); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); + $logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link)); + break; + case SAVED_NEW: + block_content_add_body_field($block_type->id()); + drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label()))); + $logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link)); + break; } $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -132,14 +132,17 @@ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; $status = $entity->save(); - if ($status === SAVED_UPDATED) { - drupal_set_message(format_string('%label configuration has been updated.', array('%label' => $entity->label()))); - } - else { - drupal_set_message(format_string('%label configuration has been created.', array('%label' => $entity->label()))); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message(format_string('%label configuration has been updated.', array('%label' => $entity->label()))); + break; + case SAVED_NEW: + drupal_set_message(format_string('%label configuration has been created.', array('%label' => $entity->label()))); + break; } $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -136,13 +136,15 @@ public function save(array $form, FormStateInterface $form_state) { $contact_settings = $this->config('contact.settings'); $edit_link = $this->entity->link($this->t('Edit')); - if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Contact form %label has been updated.', array('%label' => $contact_form->label()))); - $this->logger('contact')->notice('Contact form %label has been updated.', array('%label' => $contact_form->label(), 'link' => $edit_link)); - } - else { - drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $contact_form->label()))); - $this->logger('contact')->notice('Contact form %label has been added.', array('%label' => $contact_form->label(), 'link' => $edit_link)); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message($this->t('Contact form %label has been updated.', array('%label' => $contact_form->label()))); + $this->logger('contact')->notice('Contact form %label has been updated.', array('%label' => $contact_form->label(), 'link' => $edit_link)); + break; + case SAVED_NEW: + drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $contact_form->label()))); + $this->logger('contact')->notice('Contact form %label has been added.', array('%label' => $contact_form->label(), 'link' => $edit_link)); + break; } // Update the default form. @@ -159,6 +161,7 @@ public function save(array $form, FormStateInterface $form_state) { } $form_state->setRedirectUrl($contact_form->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -228,7 +228,8 @@ public function save(array $form, FormStateInterface $form_state) { // Save the message. In core this is a no-op but should contrib wish to // implement message storage, this will make the task of swapping in a real // storage controller straight-forward. - $message->save(); + $status = $message->save(); + return $status; } } only in patch2: unchanged: --- a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php @@ -122,10 +122,12 @@ public function exists($entity_id, array $element) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { + $status = $this->entity->save(); drupal_set_message($this->t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()))); - $this->entity->save(); + \Drupal::entityManager()->clearCachedFieldDefinitions(); $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php @@ -178,7 +178,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); + $status = $this->entity->save(); drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->entity->getLabel()))); @@ -190,6 +190,7 @@ public function save(array $form, FormStateInterface $form_state) { else { $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle())); } + return $status; } /** only in patch2: unchanged: --- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -173,7 +173,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) { $field_label = $form_state->get('field_config')->label(); try { - $this->entity->save(); + $status = $this->entity->save(); drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $field_label))); $request = $this->getRequest(); if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) { @@ -183,6 +183,7 @@ public function save(array $form, FormStateInterface $form_state) { else { $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($form_state->get('entity_type_id'), $form_state->get('bundle'))); } + return $status; } catch (\Exception $e) { drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $field_label, '%message' => $e->getMessage())), 'error'); only in patch2: unchanged: --- a/core/modules/image/src/Form/ImageStyleEditForm.php +++ b/core/modules/image/src/Form/ImageStyleEditForm.php @@ -256,8 +256,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + $status = $this->entity->save(); drupal_set_message($this->t('Changes to the style have been saved.')); + return $status; } /** only in patch2: unchanged: --- a/core/modules/image/src/Form/ImageStyleFormBase.php +++ b/core/modules/image/src/Form/ImageStyleFormBase.php @@ -77,8 +77,9 @@ public function form(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + $status = $this->entity->save(); $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); + return $status; } } only in patch2: unchanged: --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -87,7 +87,7 @@ public function form(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + $status = $this->entity->save(); $t_args = array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()); $this->logger('language')->notice('The %language (%langcode) language has been created.', $t_args); @@ -99,6 +99,8 @@ public function save(array $form, FormStateInterface $form_state) { drupal_set_message($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the block administration page.', array('@block-admin' => $this->url('block.admin_display')))); } $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + + return $status; } /** only in patch2: unchanged: --- a/core/modules/language/src/Form/LanguageEditForm.php +++ b/core/modules/language/src/Form/LanguageEditForm.php @@ -48,9 +48,10 @@ public function actions(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + $status = $this->entity->save(); $form_state->setRedirectUrl($this->entity->urlInfo('collection')); $this->logger('language')->notice('The %language (%langcode) language has been updated.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())); + return $status; } } only in patch2: unchanged: --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -122,19 +122,15 @@ public function buildEntity(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) { // The entity is rebuilt in parent::submit(). $menu_link = $this->entity; - $saved = $menu_link->save(); - - if ($saved) { - drupal_set_message($this->t('The menu link has been saved.')); - $form_state->setRedirect( - 'entity.menu_link_content.canonical', - array('menu_link_content' => $menu_link->id()) - ); - } - else { - drupal_set_message($this->t('There was an error saving the menu link.'), 'error'); - $form_state->setRebuild(); - } + $status = $menu_link->save(); + + drupal_set_message($this->t('The menu link has been saved.')); + $form_state->setRedirect( + 'entity.menu_link_content.canonical', + array('menu_link_content' => $menu_link->id()) + ); + + return $status; } } only in patch2: unchanged: --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -185,16 +185,19 @@ public function save(array $form, FormStateInterface $form_state) { $status = $menu->save(); $edit_link = $this->entity->link($this->t('Edit')); - if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label()))); - $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link)); - } - else { - drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label()))); - $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link)); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label()))); + $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link)); + break; + case SAVED_NEW: + drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label()))); + $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link)); + break; } $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); + return $status; } /** only in patch2: unchanged: --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -227,14 +227,16 @@ public function save(array $form, FormStateInterface $form_state) { $t_args = array('%name' => $type->label()); - if ($status == SAVED_UPDATED) { - drupal_set_message(t('The content type %name has been updated.', $t_args)); - } - elseif ($status == SAVED_NEW) { - node_add_body_field($type); - drupal_set_message(t('The content type %name has been added.', $t_args)); - $context = array_merge($t_args, array('link' => $type->link($this->t('View'), 'collection'))); - $this->logger('node')->notice('Added content type %name.', $context); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message(t('The content type %name has been updated.', $t_args)); + break; + case SAVED_NEW: + node_add_body_field($type); + drupal_set_message(t('The content type %name has been added.', $t_args)); + $context = array_merge($t_args, array('link' => $type->link($this->t('View'), 'collection'))); + $this->logger('node')->notice('Added content type %name.', $context); + break; } $fields = $this->entityManager->getFieldDefinitions('node', $type->id()); @@ -257,6 +259,7 @@ public function save(array $form, FormStateInterface $form_state) { $this->entityManager->clearCachedFieldDefinitions(); $form_state->setRedirectUrl($type->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -172,7 +172,7 @@ public function save(array $form, FormStateInterface $form_state) { } } } - $responsive_image_style->save(); + $status = $responsive_image_style->save(); $this->logger('responsive_image')->notice('Responsive image style @label saved.', array('@label' => $responsive_image_style->label())); drupal_set_message($this->t('Responsive image style %label saved.', array('%label' => $responsive_image_style->label()))); @@ -188,6 +188,7 @@ public function save(array $form, FormStateInterface $form_state) { else { $form_state->setRedirectUrl($this->entity->urlInfo('collection')); } + return $status; } } only in patch2: unchanged: --- a/core/modules/search/src/Form/SearchPageAddForm.php +++ b/core/modules/search/src/Form/SearchPageAddForm.php @@ -42,9 +42,10 @@ public function save(array $form, FormStateInterface $form_state) { $this->searchPageRepository->setDefaultSearchPage($this->entity); } - parent::save($form, $form_state); + $status = $this->entity-save(); drupal_set_message($this->t('The %label search page has been added.', array('%label' => $this->entity->label()))); + return $status; } } only in patch2: unchanged: --- a/core/modules/search/src/Form/SearchPageEditForm.php +++ b/core/modules/search/src/Form/SearchPageEditForm.php @@ -27,9 +27,10 @@ protected function actions(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + $status = $this->entity->save(); drupal_set_message($this->t('The %label search page has been updated.', array('%label' => $this->entity->label()))); + return $status; } } only in patch2: unchanged: --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -177,9 +177,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); + $status = $this->entity->save(); $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/shortcut/src/ShortcutForm.php +++ b/core/modules/shortcut/src/ShortcutForm.php @@ -29,11 +29,13 @@ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; $status = $entity->save(); - if ($status == SAVED_UPDATED) { - $message = $this->t('The shortcut %link has been updated.', array('%link' => $entity->getTitle())); - } - else { - $message = $this->t('Added a shortcut for %title.', array('%title' => $entity->getTitle())); + switch ($status) { + case SAVED_UPDATED: + $message = $this->t('The shortcut %link has been updated.', array('%link' => $entity->getTitle())); + break; + case SAVED_NEW: + $message = $this->t('Added a shortcut for %title.', array('%title' => $entity->getTitle())); + break; } drupal_set_message($message); @@ -41,6 +43,7 @@ public function save(array $form, FormStateInterface $form_state) { 'entity.shortcut_set.customize_form', array('shortcut_set' => $entity->bundle()) ); + return $status; } } only in patch2: unchanged: --- a/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -53,16 +53,18 @@ public function form(array $form, FormStateInterface $form_state) { */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; - $is_new = !$entity->getOriginalId(); - $entity->save(); + $status = $entity->save(); - if ($is_new) { - drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $entity->label()))); - } - else { - drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $entity->label()))); + switch ($status) { + case SAVED_NEW: + drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $entity->label()))); + break; + case SAVED_UPDATED: + drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $entity->label()))); + break; } $form_state->setRedirectUrl($this->entity->urlInfo('customize-form')); + return $status; } } only in patch2: unchanged: --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -154,13 +154,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ public function save(array $form, FormStateInterface $form_state) { $status = $this->entity->save(); - if ($status == SAVED_UPDATED) { - drupal_set_message(t('Custom date format updated.')); - } - else { - drupal_set_message(t('Custom date format added.')); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message(t('Custom date format updated.')); + break; + case SAVED_NEW: + drupal_set_message(t('Custom date format added.')); + break; } $form_state->setRedirectUrl($this->entity->urlInfo('collection')); + return $status; } } only in patch2: unchanged: --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -59,14 +59,15 @@ public function save(array $form, FormStateInterface $form_state) { $entity->setNewRevision(); } - $is_new = $entity->isNew(); - $entity->save(); + $status = $entity->save(); - if ($is_new) { - $message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId())); - } - else { - $message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId())); + switch ($status) { + case SAVED_NEW: + $message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId())); + break; + case SAVED_UPDATED: + $message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId())); + break; } drupal_set_message($message); @@ -76,6 +77,7 @@ public function save(array $form, FormStateInterface $form_state) { "entity.$entity_type.edit_form", array($entity_type => $entity->id()) ); + return $status; } else { // Error on save. only in patch2: unchanged: --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -60,15 +60,18 @@ public function save(array $form, FormStateInterface $form_state) { $status = $entity->save(); $edit_link = $this->entity->link($this->t('Edit')); - if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); - $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); - } - else { - drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); - $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); + switch ($status) { + case SAVED_UPDATED: + drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); + $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); + break; + case SAVED_NEW: + drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); + $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); + break; } $form_state->setRedirect('entity.user_role.collection'); + return $status; } }