(Moved here from http://drupal.org/node/1445124)

Current dev version doesn't correctly display tokenized title when entity is previewed rather than saved. Instead it displays "%AutoEntityLabel%" for the title.

Steps to reproduce on clean install of Drupal 7:

1. Install and enable auto_entitylabel, entity, token
2. Create a new content type with text field "field1"
3. Set "node auto label" to "Automatically generate the label and hide the label field" and in "Pattern for the title" put: [node:field_field1]
4. Create new content of that content type and preview. See attached png.

CommentFileSizeAuthor
Untitled-1.png48.54 KBrclemings
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bforchhammer’s picture

Category: bug » feature

As far as I can see this is quite hard to solve, because there's no good hook which we can use to override the data used for node previews; the ones I tested with in the past all had incomplete node objects, which means that tokens cannot be constructed properly and the title just ends up being empty (or rather the pattern string with empty placeholders).

If anyone can figure out a good way to this I'll be more than happy to add it to the module! I'm also reclassifying this as a feature request, as this is more or less by-design at the moment.

tinker’s picture

Status: Active » Needs review

What about using:


/**
 * Implements hook_node_submit().
 */
function auto_entitylabel_node_submit($node, $form, &$form_state) {
  if (auto_entitylabel_is_needed($node, $form['#entity_type'], TRUE)) {
    auto_entitylabel_set_title($node, 'node');
  };
}

I could not find a good entity hook but this problem seems to be focused on nodes. AFAIK entity functions are not called for nodes until the node is saved so cannot be used in the preview stage.

One caveat: this will probably mess up the NID token. Since NID does not exist in preview stage it will not replace it with the correct value. Later calls to auto_entitylabel_is_needed() will return FALSE so when NID is available it will not be updated.

purushotam.rai’s picture

Issue summary: View changes
Status: Needs review » Fixed

Issue no more persists, probably fixed with latest code releases.

Thanks a lot for all your inputs. Marking this issue as fixed, feel free to re-open if issue still persists.

purushotam.rai’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.