2

Is it possible to redirect a certain user type to the entry front-end page once they click on Save from the CP?

1 Answer 1

4

You'd have to write a custom plugin, that adds an event listener for the entries.saveEntry event.

The event listener should go into your plugin's primary class' init method. You'll need to make sure the event listener only fires for Control Panel requests, and that the currently logged in user is assigned to the user group you want to apply this to.

You should also make sure the entry being saved has a URL (not all entry types do) before attempting to redirect.

Here's a working example:

public function init()
{

    parent::init();

    // Get the currently logged in user
    $user = craft()->userSession->getUser();

    // Only add the event listener for Control Panel requests, and if the user is in a certain group
    if (craft()->request->isCpRequest() && $user && $user->isInGroup('userGroupHandle')) {

        craft()->on('entries.saveEntry', function (Event $event) {

            // Redirect to the entry
            $entry = $event->params['entry'];
            if ($entry->url) {
                craft()->request->redirect($entry->url);
            }

        });

    }

}

Obviously, you'll need to change the userGroupHandle string to the handle for your particular user group.

If you're unfamiliar with plugin development for Craft, I'd recommend taking a look at the Business Logic template plugin or the pluginfactory.io generator app – as well as the official docs on the subject, of course.

1
  • Awesome, thanks @Mats Mikkel Rummelhoff, works like a bomb! :) Jan 20, 2016 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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