You are here

view_mode_page.module in View Mode Page 8.3

Contains view_mode_page module.

@TODO: Custom title (optionally) per pattern path @TODO: Set canonical (optionally) per pattern path

File

view_mode_page.module
View source
<?php

/**
 * @file
 * Contains view_mode_page module.
 *
 * @TODO: Custom title (optionally) per pattern path
 * @TODO: Set canonical (optionally) per pattern path
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function view_mode_page_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.view_mode_page':
      $output = '';
      $output .= '<p>' . t('Makes it possible to create (additional) paths where entities will be shown in a given view_mode') . '</p>';
      return $output;
    case 'entity.view_mode_page_pattern.collection':
      $output = '<p>' . t('This page provides a list of all view_mode patterns on the site and allows you to edit and reorder them.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_block_build_alter().
 *
 * Adds additional cache_contexts to the system_main_block, to prevent incorrect caching of a single view_mode (when using a path alias).
 *
 * @param array $build
 * @param \Drupal\Core\Block\BlockPluginInterface $block
 */
function view_mode_page_block_build_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
  if ($block
    ->getBaseId() == 'system_main_block') {
    $build['#cache']['contexts'][] = 'url.path';
  }
}