daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Event::on(
  2.         Entry::class,
  3.         Entry::EVENT_BEFORE_SAVE,
  4.         function(ModelEvent $event){
  5.             /** @var Entry $entry */
  6.             $entry = $event->sender;
  7.  
  8.             if($entry->section == 'Question' && $entry->type=='reply') {
  9.                 if($entry->newParentId != $entry->question->id[0]){
  10.                     $entry->newParentId = $entry->question->id[0];
  11.                 }
  12.             }
  13.         });
  14.    
  15. if ($entry->newParentId) {
  16.     $parentEntry = Craft::$app->getEntries()->getEntryById($entry->newParentId, $entry->siteId);
  17.     if (!$parentEntry) {
  18.          throw new Exception('Invalid entry ID: ' . $entry->newParentId);
  19.     }
  20. } else {
  21.     $parentEntry = null;
  22. }
  23.  
  24. $entry->setParent($parentEntry);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top