Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
shortcut insert/update produce always the same message; Looking at ShortcutForm::save()
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$entity->save();
if ($entity->isNew()) {
$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()));
}
drupal_set_message($message);
....
}
- The conditions are reversed, then you should always see the wrong message.
$entity->isNew()
is called after$entity->save()
so the entity'll never be new.
Proposed resolution
Show correct message on shortcut insert/update
User interface changes
none.
API changes
none.
Comment | File | Size | Author |
---|---|---|---|
#5 | d8-shortcut-save-wrong-message-2469667-5.patch | 2.31 KB | m4olivei |
#1 | d8-shortcut-save-wrong-message-2469667-1.patch | 650 bytes | willzyx |
Comments
Comment #1
willzyx CreditAttribution: willzyx commentedComment #2
m4oliveiLooks great, tested on latest D8, patch applied clean and works as advertised. The update message shows on update now, the new message shows only when new.
@willzyx++
Comment #3
XanoNice catch! Thanks :)
Comment #4
alexpottLooks like we sh/could add an assertion somewhere for this.
Comment #5
m4oliveiSounds reasonable @alexpott. Patch attached with a couple assertions addd to look for the right message. What do you think? Totally open to critique here, I'm climbing the Drupal Ladder, and this seemed like a nice opportunity to learn some things and submit a patch.
Comment #6
willzyx CreditAttribution: willzyx commentedI do not know if this test inside a loop is a good thing. Maybe we can create a dedicated shortcut just to test the message
Comment #7
m4oliveiThat seems fair, although there are a bunch of other assertions in that loop already, doesn't seem much harm to have this in there as well. Were you thinking to create a new test case for this, to just test the message? The
testShortcutLinkAdd
method is all about operating on a list of links to create.Comment #8
jibran@willzyx I think it's not an issue. This is good to go thanks for working on this @m4olivei and @willzyx.
Comment #9
webchickHa, nice catch. That was totally wrong. :)
Looks like we have test coverage for this now too, so...
Committed and pushed to 8.0.x. Thanks!