It would be a major UX improvement if there was a way to display a preview of the fields directly on the form, e.g. "[node:title] | [site:name]" might display "Hello mum | My test site". Ideally find someone who's particularly good at this to help design the interface.

Comments

dave reid’s picture

We have this request in Pathauto and it's very hard to do once you add in entities that have not yet been saved or properly constructed into an object, and tokens like [current-page:*] which don't actually reflect the real way the meta tags would be viewed.

If we wanted to do something like the upcoming Views metatag module and insert a 'preview' of the metatags when the user actually hits the 'Preview' button on the node, that is something reliable we can use.

benjifisher’s picture

Issue summary: View changes

I was asked for this feature on a site I maintain. I am planning to implement an un-ambitious version: "Preview unavailable" when adding a new node, but the preview will be generated when you save and then edit the node. If it is not much harder, then I will make it work on Preview.

Does that sound good enough to include in the Metatag module? If so, then I will hack my copy of the module and submit a patch instead of using hook_form_alter() from a custom module.

benjifisher’s picture

Version: 7.x-1.x-dev » 7.x-1.13
Status: Active » Needs review
StatusFileSize
new2.94 KB

I have attached a patch.

As I said in my first comment, it is not very ambitious:

  • There is nothing "live" about it.
  • It only works for nodes.
  • (See David Reid's comment #1.) It fails to process [current-page:*] tokens.

The main reason for the second point (other than "good enough for my current client") is that I know I can get the node object from $form['#node'], and I am not sure what to do in general.

Status: Needs review » Needs work

The last submitted patch, 3: metatag-preview-1932404-3.patch, failed testing.

The last submitted patch, 3: metatag-preview-1932404-3.patch, failed testing.

benjifisher’s picture

Status: Needs work » Needs review
StatusFileSize
new3.41 KB

Thank you, testbot! Here is a version that does not save previews in the database.

damienmckenna’s picture

Status: Needs review » Needs work

This is an interesting idea, but it needs some work. At a basic level I would recommend doing the following:

  • Expand it to work with all entities.
  • It should work when someone loads a Preview.
  • The [current-page:] tokens won't work but are common defaults, so maybe change them to something else for the preview, or remove them and provide a comment explaining why they aren't going to work as intended? That would be better than providing wrong information.
  • The display needs work, but I'm not sure what to do to improve it.
benjifisher’s picture

Status: Needs work » Needs review
StatusFileSize
new3.53 KB

Here is an updated patch.

  • It now works with all entities, grabbing $form['#entity'] and $form['#entity_type'].
  • I forgot to mention: I did not have to do anything extra to get it to work when previewing the node (or other entity, now). It Just Works (TM).
  • I provided an option on admin/config/search/metatags/settings (under "Additional settings", which used to be a lie because there was only one) to leave tokens like [current-page:pager] unprocessed or to strip them. By default, it leaves them in.
  • I switched from a disabled textarea to a fieldset. My client asked me to make the text in the preview selectable, and maybe this will address your last point.

Thanks to the last item, I no longer have to hack the javascript to avoid polluting the vertical tab's label, and I no longer need extra code to avoid saving the preview in the metatag table.

damienmckenna’s picture

Version: 7.x-1.13 » 7.x-1.x-dev

I'll need to look at this and consider whether we want to take this approach or just try to do a real AJAX-driven preview.

damienmckenna’s picture

Status: Needs review » Needs work
Issue tags: +Usability

This needs usability work. I think we need to go back to using an AJAX structure for doing the previews, especially when not all entities support a "preview".

benjifisher’s picture

Is anyone actively working on an AJAX implementation? If not, then maybe you are letting the perfect be the enemy of the good. You could include the working, good but not perfect patch now and revert it when you come up with something better.

The patch I proposed is better than nothing. I have one happy client. The patch works with various entity types, and it works with previews.

Disclosure: I have an interest in getting this issue resolved before the next release of the module, since it will make it easier to maintain my client's site.

damienmckenna’s picture

Title: Live preview of token values » Live preview of meta tag output (D7)