/** * Creates a custom ticket type based on default settings. * * @param array $values * An array of settings to change from the defaults. * Example: 'type' => 'foo'. * * @return \Drupal\support_ticket\Entity\SupportTicketType * Created support ticket type. */ protected function supportTicketCreateSupportTicketType(array $values = array()) { // Find a non-existent random type name. if (!isset($values['type'])) { do { $id = strtolower($this->randomMachineName(8)); } while (SupportTicketType::load($id)); } else { $id = $values['type']; } $values += array('type' => $id, 'name' => $id); $type = entity_create('support_ticket_type', $values); $status = $type->save(); support_ticket_add_body_field($type); \Drupal::service('router.builder')->rebuild(); $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created support ticket type %type.', array('%type' => $type->id()))); return $type; }
/** * Builds a standard list of support ticket permissions for a given type. * * @param \Drupal\support_ticket\Entity\SupportTicketType $type * The machine name of the support ticket type. * * @return array * An array of permission names and descriptions. */ protected function buildPermissions(SupportTicketType $type) { $type_id = $type->id(); $type_params = array('%type_name' => $type->label()); return array("create {$type_id} ticket" => array('title' => $this->t('%type_name: Create new ticket', $type_params)), "edit own {$type_id} ticket" => array('title' => $this->t('%type_name: Edit own ticket', $type_params)), "edit any {$type_id} ticket" => array('title' => $this->t('%type_name: Edit any ticket', $type_params)), "delete own {$type_id} ticket" => array('title' => $this->t('%type_name: Delete own ticket', $type_params)), "delete any {$type_id} ticket" => array('title' => $this->t('%type_name: Delete any ticket', $type_params)), "view {$type_id} revisions" => array('title' => $this->t('%type_name: View revisions', $type_params)), "modify locked {$type_id} ticket" => array('title' => $this->t('%type_name: Modify locked ticket', $type_params)), "revert {$type_id} revisions" => array('title' => $this->t('%type_name: Revert revisions', $type_params), 'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for support tickets in question, or <em>administer support tickets</em>.')), "delete {$type_id} revisions" => array('title' => $this->t('%type_name: Delete revisions', $type_params), 'description' => $this->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for support tickets in question, or <em>administer support tickets</em>.'))); }