class SupportTicketController in Support Ticketing System 8
Returns responses for Support Ticket routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\support_ticket\Controller\SupportTicketController implements ContainerInjectionInterface
Expanded class hierarchy of SupportTicketController
File
- modules/
support_ticket/ src/ Controller/ SupportTicketController.php, line 22 - Contains \Drupal\support_ticket\Controller\SupportTicketController.
Namespace
Drupal\support_ticket\ControllerView source
class SupportTicketController extends ControllerBase implements ContainerInjectionInterface {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a SupportTicketController object.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer) {
$this->dateFormatter = $date_formatter;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('date.formatter'), $container
->get('renderer'));
}
/**
* Displays add content links for available support ticket types.
*
* Redirects to support_ticket/add/[type] if only one support ticket type is available.
*
* @return array
* A render array for a list of the support ticket types that can be added; however,
* if there is only one support ticket type defined for the site, the function
* redirects to the support ticket add page for that one support ticket type and does
* not return at all.
*
* @see support_ticket_menu()
*/
public function addPage() {
$build = [
'#theme' => 'support_ticket_add_list',
'#cache' => [
'tags' => $this
->entityManager()
->getDefinition('support_ticket_type')
->getListCacheTags(),
],
];
$types = array();
// Only use support ticket types the user has access to.
foreach ($this
->entityManager()
->getStorage('support_ticket_type')
->loadMultiple() as $type) {
$access = $this
->entityManager()
->getAccessControlHandler('support_ticket')
->createAccess($type
->id(), NULL, [], TRUE);
if ($access
->isAllowed()) {
$types[$type
->id()] = $type;
}
$this->renderer
->addCacheableDependency($build, $access);
}
// Bypass the support_ticket/add listing if only one support ticket type is available.
if (count($types) == 1) {
$type = array_shift($types);
return $this
->redirect('support_ticket.add', array(
'support_ticket_type' => $type
->id(),
));
}
$build['#content'] = $types;
return $build;
}
/**
* Provides the support ticket submission form.
*
* @param \Drupal\support_ticket\SupportTicketTypeInterface $support_ticket_type
* The support ticket type entity for the support ticket.
*
* @return array
* A support ticket submission form.
*/
public function add(SupportTicketTypeInterface $support_ticket_type) {
$support_ticket = $this
->entityManager()
->getStorage('support_ticket')
->create(array(
'support_ticket_type' => $support_ticket_type
->id(),
));
$form = $this
->entityFormBuilder()
->getForm($support_ticket);
return $form;
}
/**
* Displays a support_ticket revision.
*
* @param int $supprt_ticket_revision
* The support ticket revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($support_ticket_revision) {
$support_ticket = $this
->entityManager()
->getStorage('support_ticket')
->loadRevision($support_ticket_revision);
$support_ticket_view_controller = new SupportTicketViewController($this->entityManager, $this->renderer);
$page = $support_ticket_view_controller
->view($support_ticket);
unset($page['support_tickets'][$support_ticket
->id()]['#cache']);
return $page;
}
/**
* Page title callback for a support ticket revision.
*
* @param int $support_ticket_revision
* The support ticket revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle($support_ticket_revision) {
$support_ticket = $this
->entityManager()
->getStorage('support_ticket')
->loadRevision($support_ticket_revision);
return $this
->t('Revision of %title from %date', array(
'%title' => $support_ticket
->label(),
'%date' => format_date($support_ticket
->getRevisionCreationTime()),
));
}
/**
* Generates an overview table of older revisions of a support ticket.
*
* @param \Drupal\support_ticket\SupportTicketInterface $support_ticket
* A support_ticket object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview(SupportTicketInterface $support_ticket) {
$account = $this
->currentUser();
$support_ticket_storage = $this
->entityManager()
->getStorage('support_ticket');
$type = $support_ticket
->getType();
$build = array();
$build['#title'] = $this
->t('Revisions for %title', array(
'%title' => $support_ticket
->label(),
));
$header = array(
$this
->t('Revision'),
$this
->t('Operations'),
);
$revert_permission = ($account
->hasPermission("revert {$type} revisions") || $account
->hasPermission('revert all revisions') || $account
->hasPermission('administer support tickets')) && $support_ticket
->access('update');
$delete_permission = ($account
->hasPermission("delete {$type} revisions") || $account
->hasPermission('delete all revisions') || $account
->hasPermission('administer support tickets')) && $support_ticket
->access('delete');
$rows = array();
$vids = $support_ticket_storage
->revisionIds($support_ticket);
foreach (array_reverse($vids) as $vid) {
$revision = $support_ticket_storage
->loadRevision($vid);
$username = [
'#theme' => 'username',
'#account' => $revision->uid->entity,
];
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter
->format($revision->revision_timestamp->value, 'short');
if ($vid != $support_ticket
->getRevisionId()) {
$link = $this
->l($date, new Url('entity.support_ticket.revision', [
'support_ticket' => $support_ticket
->id(),
'support_ticket_revision' => $vid,
]));
}
else {
$link = $support_ticket
->link($date);
}
$row = [];
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
'#context' => [
'date' => $link,
'username' => $this->renderer
->renderPlain($username),
'message' => [
'#markup' => $revision->revision_log->value,
],
],
],
];
// @todo Simplify once https://www.drupal.org/node/2334319 lands.
$this->renderer
->addCacheableDependency($column['data'], $username);
$row[] = $column;
if ($vid == $support_ticket
->getRevisionId()) {
$row[0]['class'] = [
'revision-current',
];
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this
->t('current revision'),
'#suffix' => '</em>',
],
'class' => [
'revision-current',
],
];
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this
->t('Revert'),
'url' => Url::fromRoute('support_ticket.revision_revert_confirm', [
'support_ticket' => $support_ticket
->id(),
'support_ticket_revision' => $vid,
]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('support_ticket.revision_delete_confirm', [
'support_ticket' => $support_ticket
->id(),
'support_ticket_revision' => $vid,
]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
$build['support_ticket_revisions_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
'#attached' => array(
'library' => array(
'support_ticket/drupal.support_ticket.admin',
),
),
);
return $build;
}
/**
* The _title_callback for the support_ticket.add route.
*
* @param \Drupal\support_ticket\SupportTicketTypeInterface $support_ticket_type
* The current support ticket.
*
* @return string
* The page title.
*/
public function addPageTitle(SupportTicketTypeInterface $support_ticket_type) {
return $this
->t('Create @name', array(
'@name' => $support_ticket_type
->label(),
));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
SupportTicketController:: |
protected | property | The date formatter service. | |
SupportTicketController:: |
protected | property | The renderer service. | |
SupportTicketController:: |
public | function | Provides the support ticket submission form. | |
SupportTicketController:: |
public | function | Displays add content links for available support ticket types. | |
SupportTicketController:: |
public | function | The _title_callback for the support_ticket.add route. | |
SupportTicketController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
SupportTicketController:: |
public | function | Generates an overview table of older revisions of a support ticket. | |
SupportTicketController:: |
public | function | Page title callback for a support ticket revision. | |
SupportTicketController:: |
public | function | Displays a support_ticket revision. | |
SupportTicketController:: |
public | function | Constructs a SupportTicketController object. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |