You are here

class LeafletAjaxPopupController in Leaflet 2.1.x

Same name and namespace in other branches
  1. 8 modules/leaflet_views/src/Controller/LeafletAjaxPopupController.php \Drupal\leaflet_views\Controller\LeafletAjaxPopupController
  2. 2.0.x modules/leaflet_views/src/Controller/LeafletAjaxPopupController.php \Drupal\leaflet_views\Controller\LeafletAjaxPopupController

Default controller for the leaflet_views_ajax_popup module.

Hierarchy

Expanded class hierarchy of LeafletAjaxPopupController

1 file declares its use of LeafletAjaxPopupController
LeafletMap.php in modules/leaflet_views/src/Plugin/views/style/LeafletMap.php

File

modules/leaflet_views/src/Controller/LeafletAjaxPopupController.php, line 17

Namespace

Drupal\leaflet_views\Controller
View source
class LeafletAjaxPopupController extends ControllerBase {

  /**
   * The Entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityManager;

  /**
   * The Renderer service property.
   *
   * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
   */
  protected $renderer;

  /**
   * Constructs a new LeafletAjaxPopupController object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager, RendererInterface $renderer) {
    $this->entityManager = $entity_manager;
    $this->renderer = $renderer;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('renderer'));
  }

  /**
   * User LeafletAjaxPopup page access checker.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to check the permission for view.
   *
   * @return \Drupal\Core\Access\AccessResult
   *   The Access check results.
   */
  public function accessCheck(EntityInterface $entity) {
    return AccessResult::allowedIf($entity
      ->access('view'));
  }

  /**
   * Leaflet Ajax Popup build callback..
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity whose build to return.
   * @param string $view_mode
   *   The view mode identifier.
   * @param string $langcode
   *   The langcode to render the entity by.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The Response to return.
   */
  public function popupBuild(EntityInterface $entity, $view_mode, $langcode = NULL) {
    $entity_view_builder = $this->entityManager
      ->getViewBuilder($entity
      ->getEntityTypeId());
    $build = $entity_view_builder
      ->view($entity, $view_mode, $langcode);
    $response = new AjaxResponse();
    $response
      ->addCommand(new ReplaceCommand($this
      ->getPopupIdentifierSelector($entity
      ->getEntityTypeId(), $entity
      ->id(), $view_mode, $langcode), $build));
    return $response;
  }

  /**
   * Get popup identifier.
   *
   * @param string $entityType
   *   The entity type.
   * @param int $entityId
   *   The entity id.
   * @param string $viewMode
   *   The view mode.
   * @param string $langcode
   *   The langcode.
   *
   * @return string
   *   The identifier.
   */
  public static function getPopupIdentifier($entityType, $entityId, $viewMode, $langcode) {
    return "{$entityType}-{$entityId}-{$viewMode}-{$langcode}";
  }

  /**
   * Get popup identifier attribute.
   *
   * @param string $entityType
   *   The entity type.
   * @param int $entityId
   *   The entity id.
   * @param string $viewMode
   *   The view mode.
   * @param string $langcode
   *   The langcode.
   *
   * @return string
   *   The identifier selector.
   */
  public static function getPopupIdentifierAttribute($entityType, $entityId, $viewMode, $langcode) {
    return sprintf('data-leaflet-popup-ajax-entity="%s"', self::getPopupIdentifier($entityType, $entityId, $viewMode, $langcode));
  }

  /**
   * Get popup identifier selector.
   *
   * @param string $entityType
   *   The entity type.
   * @param int $entityId
   *   The entity id.
   * @param string $viewMode
   *   The view mode.
   * @param string $langcode
   *   The langcode.
   *
   * @return string
   *   The identifier selector.
   */
  public static function getPopupIdentifierSelector($entityType, $entityId, $viewMode, $langcode) {
    return sprintf('[%s]', self::getPopupIdentifierAttribute($entityType, $entityId, $viewMode, $langcode));
  }

}

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.
LeafletAjaxPopupController::$entityManager protected property The Entity type manager service.
LeafletAjaxPopupController::$renderer protected property The Renderer service property.
LeafletAjaxPopupController::accessCheck public function User LeafletAjaxPopup page access checker.
LeafletAjaxPopupController::create public static function Instantiates a new instance of this class. Overrides ControllerBase::create
LeafletAjaxPopupController::getPopupIdentifier public static function Get popup identifier.
LeafletAjaxPopupController::getPopupIdentifierAttribute public static function Get popup identifier attribute.
LeafletAjaxPopupController::getPopupIdentifierSelector public static function Get popup identifier selector.
LeafletAjaxPopupController::popupBuild public function Leaflet Ajax Popup build callback..
LeafletAjaxPopupController::__construct public function Constructs a new LeafletAjaxPopupController object.
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.