You are here

class BibciteEntityPreviewController in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Controller/BibciteEntityPreviewController.php \Drupal\bibcite_entity\Controller\BibciteEntityPreviewController

Defines a controller to render a single bibcite entity in preview.

Hierarchy

Expanded class hierarchy of BibciteEntityPreviewController

File

modules/bibcite_entity/src/Controller/BibciteEntityPreviewController.php, line 15

Namespace

Drupal\bibcite_entity\Controller
View source
class BibciteEntityPreviewController extends EntityViewController {

  /**
   * Entity repository service.
   *
   * @var \Drupal\Core\Entity\EntityRepositoryInterface
   */
  protected $repository;

  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, EntityRepositoryInterface $repository) {
    parent::__construct($entity_type_manager, $renderer);
    $this->repository = $repository;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
    $entity_manager = $container
      ->get('entity_type.manager');

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $container
      ->get('renderer');

    /** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
    $repository = $container
      ->get('entity.repository');
    return new static($entity_manager, $renderer, $repository);
  }

  /**
   * {@inheritdoc}
   */
  public function view(EntityInterface $bibcite_reference_preview, $view_mode_id = 'default', $langcode = NULL) {
    $bibcite_reference_preview->preview_view_mode = $view_mode_id;
    $build = parent::view($bibcite_reference_preview, $view_mode_id);
    $build['#attached']['library'][] = 'bibcite_entity/reference.preview';

    // Don't render cache previews.
    unset($build['#cache']);
    return $build;
  }

  /**
   * The _title_callback for the page that renders a reference in preview.
   *
   * @param \Drupal\Core\Entity\EntityInterface $bibcite_reference_preview
   *   The current reference entity.
   *
   * @return string
   *   The page title.
   */
  public function title(EntityInterface $bibcite_reference_preview) {
    return $this->repository
      ->getTranslationFromContext($bibcite_reference_preview)
      ->label();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BibciteEntityPreviewController::$repository protected property Entity repository service.
BibciteEntityPreviewController::create public static function Instantiates a new instance of this class. Overrides EntityViewController::create
BibciteEntityPreviewController::title public function The _title_callback for the page that renders a reference in preview.
BibciteEntityPreviewController::view public function Provides a page to render a single entity. Overrides EntityViewController::view
BibciteEntityPreviewController::__construct public function Creates an EntityViewController object. Overrides EntityViewController::__construct
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityViewController::$deprecatedProperties protected property
EntityViewController::$entityTypeManager protected property The entity type manager.
EntityViewController::$renderer protected property The renderer service.
EntityViewController::buildTitle public function Pre-render callback to build the page title.
EntityViewController::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
EntityViewController::viewRevision public function Provides a page to render a single entity revision.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.