Created
February 16, 2018 10:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the
10
with the ID of the section you want this to apply to