You are here

class EntityLegalController in Entity Legal 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Controller/EntityLegalController.php \Drupal\entity_legal\Controller\EntityLegalController
  2. 3.0.x src/Controller/EntityLegalController.php \Drupal\entity_legal\Controller\EntityLegalController

Class EntityLegalController.

@package Drupal\entity_legal\Controller

Hierarchy

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\Controller
View 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

Namesort descending Modifiers Type Description Overrides
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$formBuilder protected property The form builder. 2
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route.
ControllerBase::state protected function Returns the state storage service.
EntityLegalController::$entityLegalDocumentVersionStorage protected property The entity legal document version storage.
EntityLegalController::$token protected property The token service.
EntityLegalController::create public static function Instantiates a new instance of this class. Overrides ControllerBase::create
EntityLegalController::documentEditPageTitle public function Page title callback for the Entity Legal Document edit form.
EntityLegalController::documentPage public function Page callback for the Entity Legal Document.
EntityLegalController::documentPageTitle public function Page title callback for the Entity Legal Document.
EntityLegalController::documentVersionAddFormTitle public function Page title callback for the Entity Legal Document Version add form.
EntityLegalController::documentVersionEditFormTitle public function Page title callback for the Entity Legal Document Version edit form.
EntityLegalController::documentVersionForm public function Page callback for the Entity Legal Document Version form.
EntityLegalController::__construct public function EntityLegalController constructor.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.