class EntityLegalController in Entity Legal 4.0.x
Same name and namespace in other branches
- 8.2 src/Controller/EntityLegalController.php \Drupal\entity_legal\Controller\EntityLegalController
- 3.0.x src/Controller/EntityLegalController.php \Drupal\entity_legal\Controller\EntityLegalController
Class EntityLegalController.
@package Drupal\entity_legal\Controller
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\entity_legal\Controller\EntityLegalController
Expanded class hierarchy of EntityLegalController
1 file declares its use of EntityLegalController
- DocumentTest.php in tests/
src/ Kernel/ DocumentTest.php
File
- src/
Controller/ EntityLegalController.php, line 19
Namespace
Drupal\entity_legal\ControllerView source
class EntityLegalController extends ControllerBase {
/**
* The entity legal document version storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityLegalDocumentVersionStorage;
/**
* The token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME), $container
->get('token'));
}
/**
* EntityLegalController constructor.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_legal_document_version_storage
* The custom block storage.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/
public function __construct(EntityStorageInterface $entity_legal_document_version_storage, Token $token) {
$this->entityLegalDocumentVersionStorage = $entity_legal_document_version_storage;
$this->token = $token;
}
/**
* Page title callback for the Entity Legal Document edit form.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $entity_legal_document
* The Entity Legal Document entity.
*/
public function documentEditPageTitle(EntityLegalDocumentInterface $entity_legal_document) {
return $this
->t('Edit %label', [
'%label' => $entity_legal_document
->label(),
]);
}
/**
* Page callback for the Entity Legal Document.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $entity_legal_document
* The Entity Legal Document entity.
* @param \Drupal\entity_legal\EntityLegalDocumentVersionInterface|null $entity_legal_document_version
* The Entity Legal Document version entity.
*/
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 specified version is unpublished, display a message.
if ($entity_legal_document_version
->id() != $entity_legal_document
->getPublishedVersion()
->id()) {
\Drupal::messenger()
->addMessage('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);
}
/**
* Page title callback for the Entity Legal Document.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $entity_legal_document
* The Entity Legal Document entity.
* @param \Drupal\entity_legal\EntityLegalDocumentVersionInterface|null $entity_legal_document_version
* The Entity Legal Document version entity.
*/
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,
]);
}
/**
* Page callback for the Entity Legal Document Version form.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $entity_legal_document
* The entity legal document.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A form array as expected by drupal_render().
*/
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);
}
/**
* Page title callback for the Entity Legal Document Version add form.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $entity_legal_document
* The entity legal document.
*
* @return string
* The page title.
*/
public function documentVersionAddFormTitle(EntityLegalDocumentInterface $entity_legal_document) {
return $this
->t('Add %type legal document version', [
'%type' => $entity_legal_document
->label(),
]);
}
/**
* Page title callback for the Entity Legal Document Version edit form.
*
* @param string $entity_legal_document
* The entity legal document id.
* @param \Drupal\entity_legal\EntityLegalDocumentVersionInterface $entity_legal_document_version
* The Entity Legal Document version entity.
*
* @return string
* The page title.
*/
public function documentVersionEditFormTitle($entity_legal_document, EntityLegalDocumentVersionInterface $entity_legal_document_version) {
return $this
->t('Edit %label', [
'%label' => $entity_legal_document_version
->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 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. | |
EntityLegalController:: |
protected | property | The entity legal document version storage. | |
EntityLegalController:: |
protected | property | The token service. | |
EntityLegalController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
EntityLegalController:: |
public | function | Page title callback for the Entity Legal Document edit form. | |
EntityLegalController:: |
public | function | Page callback for the Entity Legal Document. | |
EntityLegalController:: |
public | function | Page title callback for the Entity Legal Document. | |
EntityLegalController:: |
public | function | Page title callback for the Entity Legal Document Version add form. | |
EntityLegalController:: |
public | function | Page title callback for the Entity Legal Document Version edit form. | |
EntityLegalController:: |
public | function | Page callback for the Entity Legal Document Version form. | |
EntityLegalController:: |
public | function | EntityLegalController constructor. | |
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. | |
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. |