class ProjectController in Drupal PM (Project Management) 4.x
Class ProjectController.
Returns responses for Project routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\pm_project\Controller\ProjectController implements ContainerInjectionInterface
Expanded class hierarchy of ProjectController
File
- modules/
pm_project/ src/ Controller/ ProjectController.php, line 18
Namespace
Drupal\pm_project\ControllerView source
class ProjectController extends ControllerBase implements ContainerInjectionInterface {
/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatter
*/
protected $dateFormatter;
/**
* The renderer.
*
* @var \Drupal\Core\Render\Renderer
*/
protected $renderer;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->dateFormatter = $container
->get('date.formatter');
$instance->renderer = $container
->get('renderer');
return $instance;
}
/**
* Displays a Project revision.
*
* @param int $pm_project_revision
* The Project revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($pm_project_revision) {
$pm_project = $this
->entityTypeManager()
->getStorage('pm_project')
->loadRevision($pm_project_revision);
$view_builder = $this
->entityTypeManager()
->getViewBuilder('pm_project');
return $view_builder
->view($pm_project);
}
/**
* Page title callback for a Project revision.
*
* @param int $pm_project_revision
* The Project revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle($pm_project_revision) {
$pm_project = $this
->entityTypeManager()
->getStorage('pm_project')
->loadRevision($pm_project_revision);
return $this
->t('Revision of %title from %date', [
'%title' => $pm_project
->label(),
'%date' => $this->dateFormatter
->format($pm_project
->getRevisionCreationTime()),
]);
}
/**
* Generates an overview table of older revisions of a Project.
*
* @param \Drupal\pm_project\Entity\ProjectInterface $pm_project
* A Project object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview(ProjectInterface $pm_project) {
$account = $this
->currentUser();
$pm_project_storage = $this
->entityTypeManager()
->getStorage('pm_project');
$build['#title'] = $this
->t('Revisions for %title', [
'%title' => $pm_project
->label(),
]);
$header = [
$this
->t('Revision'),
$this
->t('Operations'),
];
$revert_permission = $account
->hasPermission("revert all project revisions") || $account
->hasPermission('administer project entities');
$delete_permission = $account
->hasPermission("delete all project revisions") || $account
->hasPermission('administer project entities');
$rows = [];
$vids = $pm_project_storage
->revisionIds($pm_project);
$latest_revision = TRUE;
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\pm_project\ProjectInterface $revision */
$revision = $pm_project_storage
->loadRevision($vid);
$username = [
'#theme' => 'username',
'#account' => $revision
->getRevisionUser(),
];
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter
->format($revision
->getRevisionCreationTime(), 'short');
if ($vid != $pm_project
->getRevisionId()) {
$link = Link::fromTextAndUrl($date, new Url('entity.pm_project.revision', [
'pm_project' => $pm_project
->id(),
'pm_project_revision' => $vid,
]));
}
else {
$link = $pm_project
->toLink()
->toString($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
->getRevisionLogMessage(),
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
],
];
$row[] = $column;
if ($latest_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this
->t('Current revision'),
'#suffix' => '</em>',
],
];
foreach ($row as &$current) {
$current['class'] = [
'revision-current',
];
}
$latest_revision = FALSE;
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this
->t('Revert'),
'url' => Url::fromRoute('entity.pm_project.revision_revert', [
'pm_project' => $pm_project
->id(),
'pm_project_revision' => $vid,
]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('entity.pm_project.revision_delete', [
'pm_project' => $pm_project
->id(),
'pm_project_revision' => $vid,
]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
$build['pm_project_revisions_table'] = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
];
return $build;
}
}
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 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 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. | |
ControllerBase:: |
protected | function | Returns the state storage 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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
ProjectController:: |
protected | property | The date formatter. | |
ProjectController:: |
protected | property | The renderer. | |
ProjectController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
ProjectController:: |
public | function | Generates an overview table of older revisions of a Project. | |
ProjectController:: |
public | function | Page title callback for a Project revision. | |
ProjectController:: |
public | function | Displays a Project revision. | |
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. | 4 |
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. |