/** * #lazy_builder callback; builds a support ticket's links. * * @param string $support_ticket_entity_id * The support ticket entity ID. * @param string $view_mode * The view mode in which the support ticket entity is being viewed. * @param string $langcode * The language in which the support ticket entity is being viewed. * * @return array * A renderable array representing the support ticket links. */ public static function renderLinks($support_ticket_entity_id, $view_mode, $langcode) { $links = array('#theme' => 'links__support_ticket', '#pre_render' => array('drupal_pre_render_links'), '#attributes' => array('class' => array('links', 'inline'))); $entity = SupportTicket::load($support_ticket_entity_id)->getTranslation($langcode); $links['support_ticket'] = static::buildLinks($entity, $view_mode); // Allow other modules to alter the support_ticket links. $hook_context = array('view_mode' => $view_mode, 'langcode' => $langcode); \Drupal::moduleHandler()->alter('support_ticket_links', $links, $entity, $hook_context); return $links; }
/** * Tests support_ticket presave and static support_ticket load cache. * * This test determines changes in hook_ENTITY_TYPE_presave() and verifies * that the static support_ticket load cache is cleared upon save. */ function testDeterminingChanges() { // Initial creation. $support_ticket = entity_create('support_ticket', array('uid' => $this->webUser->id(), 'support_ticket_type' => 'ticket', 'title' => 'test_changes')); $support_ticket->save(); // Update the support_ticket without applying changes. $support_ticket->save(); $this->assertEqual($support_ticket->label(), 'test_changes', 'No changes have been determined.'); // Apply changes. $support_ticket->title = 'updated'; $support_ticket->save(); // The hook implementations support_ticket_test_support_ticket_presave() and // support_ticket_test_support_ticket_update() determine changes and change the title. $this->assertEqual($support_ticket->label(), 'updated_presave_update', 'Changes have been determined.'); // Test the static support_ticket load cache to be cleared. $support_ticket = SupportTicket::load($support_ticket->id()); $this->assertEqual($support_ticket->label(), 'updated_presave', 'Static cache has been cleared.'); }