Skip to content

Instantly share code, notes, and snippets.

@mdcpepper
Created February 16, 2018 10:26
Show Gist options
  • Save mdcpepper/f2a7aa953efe3b15895cf552d2ccc0ac to your computer and use it in GitHub Desktop.
Save mdcpepper/f2a7aa953efe3b15895cf552d2ccc0ac to your computer and use it in GitHub Desktop.
Move Entries to the top of a structure when they're first saved
class YourPlugin extends BasePlugin
{
public function init()
{
craft()->on('entries.onSaveEntry', function(Event $event)
{
$isNewEntry = $event->params['isNewEntry'];
if (!$isNewEntry)
{
return;
}
/** @var EntryModel $entry */
$entry = $event->params['entry'];
if ((int) $entry->sectionId !== 10)
{
return;
}
craft()->structures->prependToRoot($entry->getSection()->structureId, $entry);
});
}
}
@mdcpepper
Copy link
Author

Replace the 10 with the ID of the section you want this to apply to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment