4

How would I go about to get the author from the current version / revision of the entry I'm on? Im trying to get "last updated by" in frontend, but authorId on the entry seems to be the original author, not the last that edited it.

2

Craft includes a function called getVersionsByEntryId, but its full functionality isn't exposed by default. You have to create a template variable to get the most recent version.

If you only need the most recent version, you can add the following to your plugin's variables:

/**
 * @param  EntryModel $entry The entry to search for.
 * @return EntryVersionModel
 */
public function getCurrentVersion($entry)
{
  $versions = craft()->entryRevisions->getVersionsByEntryId($entry->id, $entry->locale, 1, true);
  return reset($versions);
}

Then you can grab the author within your templates with the following:

{{ craft.pluginName.getCurrentVersion(entry).creator }}
4

You have to write a template variable that makes getVersionsByEntryId() available in Twig.

public function getVersionsByEntryId($entryId, $localeId, $limit = 1, $includeCurrent = true)
{
    return craft()->entryRevisions->getVersionsByEntryId($entryId, $localeId, $limit, $includeCurrent);
}

You can now access an entry’s versions and get the current version’s creator like so.

{% set versions = craft.businessLogic.getVersionsByEntryId(entry.id, entry.locale) %}
{% set author = versions|length ? versions[0].creator : entry.author %}

{{ author.fullName }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.