/** * @covers ::postLoad */ public function testPostLoad() { // This method is internal, so check for errors on calling it only. $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); $entities = array($this->entity); // Our mocked entity->postLoad() returns NULL, so assert that. $this->assertNull($this->entity->postLoad($storage, $entities)); }
/** * {@inheritdoc} */ public static function postLoad(EntityStorageInterface $storage, array &$entities) { parent::postLoad($storage, $entities); $routes = array(); foreach ($entities as $menu_link) { $menu_link->options = unserialize($menu_link->options); $menu_link->route_parameters = unserialize($menu_link->route_parameters); // By default use the menu_name as type. $menu_link->bundle = $menu_link->menu_name; // For all links that have an associated route, load the route object now // and save it on the object. That way we avoid a select N+1 problem later. if ($menu_link->route_name) { $routes[$menu_link->id()] = $menu_link->route_name; } } // Now mass-load any routes needed and associate them. if ($routes) { $route_objects = \Drupal::service('router.route_provider')->getRoutesByNames($routes); foreach ($routes as $entity_id => $route) { // Not all stored routes will be valid on load. if (isset($route_objects[$route])) { $entities[$entity_id]->setRouteObject($route_objects[$route]); } } } }