Created
October 17, 2016 17:05
-
-
Save mglaman/3c76f65c8efcd4dcdd3b45dfbefd8518 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| public function postSave(EntityStorageInterface $storage, $update = TRUE) { | |
| $rating = $this->get('rating')->first()->value; | |
| /** @var \Drupal\forkdin_restaurant\Entity\RestaurantMenuItem $menu_item */ | |
| $menu_item = $this->get('menu_item_id')->entity; | |
| $vote = Vote::create([ | |
| 'type' => 'rating', | |
| 'entity_type' => 'checkin', | |
| 'entity_id' => $menu_item->id(), | |
| 'value' => $rating, | |
| 'value_type' => 'points', | |
| 'user_id' => $this->getOwner(), | |
| ]); | |
| $vote->save(); | |
| /** @var \Drupal\votingapi\VoteResultFunctionManager $result_function */ | |
| $result_function = \Drupal::service('plugin.manager.votingapi.resultfunction'); | |
| $results = $result_function->getResults('checkin', $menu_item->id()); | |
| $menu_item->setRating($results['rating']['vote_average']); | |
| $menu_item->save(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment