EntityLegalController.php in Entity Legal 8.2
File
src/Controller/EntityLegalController.php
View source
<?php
namespace Drupal\entity_legal\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Utility\Token;
use Drupal\entity_legal\EntityLegalDocumentInterface;
use Drupal\entity_legal\EntityLegalDocumentVersionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EntityLegalController extends ControllerBase {
protected $entityLegalDocumentVersionStorage;
protected $token;
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME), $container
->get('token'));
}
public function __construct(EntityStorageInterface $entity_legal_document_version_storage, Token $token) {
$this->entityLegalDocumentVersionStorage = $entity_legal_document_version_storage;
$this->token = $token;
}
public function documentEditPageTitle(EntityLegalDocumentInterface $entity_legal_document) {
return $this
->t('Edit %label', [
'%label' => $entity_legal_document
->label(),
]);
}
public function documentPage(EntityLegalDocumentInterface $entity_legal_document, EntityLegalDocumentVersionInterface $entity_legal_document_version = NULL) {
if (is_null($entity_legal_document_version)) {
$entity_legal_document_version = $entity_legal_document
->getPublishedVersion();
if (!$entity_legal_document_version) {
throw new NotFoundHttpException();
}
}
if ($entity_legal_document_version
->id() != $entity_legal_document
->getPublishedVersion()
->id()) {
drupal_set_message('You are viewing an unpublished version of this legal document.', 'warning');
}
return \Drupal::entityTypeManager()
->getViewBuilder(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME)
->view($entity_legal_document_version);
}
public function documentPageTitle(EntityLegalDocumentInterface $entity_legal_document, EntityLegalDocumentVersionInterface $entity_legal_document_version = NULL) {
if (is_null($entity_legal_document_version)) {
$entity_legal_document_version = $entity_legal_document
->getPublishedVersion();
}
$pattern = $entity_legal_document
->get('settings')['title_pattern'];
return $this->token
->replace($pattern, [
ENTITY_LEGAL_DOCUMENT_ENTITY_NAME => $entity_legal_document,
]);
}
public function documentVersionForm(EntityLegalDocumentInterface $entity_legal_document, Request $request) {
$entity_legal_document_version = $this->entityLegalDocumentVersionStorage
->create([
'document_name' => $entity_legal_document
->id(),
]);
return $this
->entityFormBuilder()
->getForm($entity_legal_document_version);
}
public function documentVersionAddFormTitle(EntityLegalDocumentInterface $entity_legal_document) {
return $this
->t('Add %type legal document version', [
'%type' => $entity_legal_document
->label(),
]);
}
public function documentVersionEditFormTitle($entity_legal_document, EntityLegalDocumentVersionInterface $entity_legal_document_version) {
return $this
->t('Edit %label', [
'%label' => $entity_legal_document_version
->label(),
]);
}
}