You are here

class WorkbenchPreprocess in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 src/WorkbenchPreprocess.php \Drupal\workbench_moderation\WorkbenchPreprocess

Service to determine whether a route is the "Latest version" tab of a node.

Hierarchy

Expanded class hierarchy of WorkbenchPreprocess

1 file declares its use of WorkbenchPreprocess
WorkbenchPreprocessTest.php in tests/src/Unit/WorkbenchPreprocessTest.php
1 string reference to 'WorkbenchPreprocess'
workbench_moderation.services.yml in ./workbench_moderation.services.yml
workbench_moderation.services.yml
1 service uses WorkbenchPreprocess
workbench_moderation.workbench_preprocess in ./workbench_moderation.services.yml
Drupal\workbench_moderation\WorkbenchPreprocess

File

src/WorkbenchPreprocess.php, line 11

Namespace

Drupal\workbench_moderation
View source
class WorkbenchPreprocess {

  /**
   * Current route match.
   *
   * @var \Drupal\Core\Routing\CurrentRouteMatch
   */
  protected $routeMatch;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Routing\CurrentRouteMatch $route_match
   *   Current route match service.
   */
  public function __construct(CurrentRouteMatch $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * Wrapper for hook_preprocess_HOOK().
   *
   * @param array $variables
   *   Theme variables to preprocess.
   */
  public function preprocessNode(array &$variables) {

    // Set the 'page' template variable when the node is being displayed on the
    // "Latest version" tab provided by workbench_moderation.
    $variables['page'] = $variables['page'] || $this
      ->isLatestVersionPage($variables['node']);
  }

  /**
   * Checks whether a route is the "Latest version" tab of a node.
   *
   * @param \Drupal\node\Entity\Node $node
   *   A node.
   *
   * @return bool
   *   True if the current route is the latest version tab of the given node.
   */
  public function isLatestVersionPage(Node $node) {
    return $this->routeMatch
      ->getRouteName() == 'entity.node.latest_version' && ($pageNode = $this->routeMatch
      ->getParameter('node')) && $pageNode
      ->id() == $node
      ->id();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WorkbenchPreprocess::$routeMatch protected property Current route match.
WorkbenchPreprocess::isLatestVersionPage public function Checks whether a route is the "Latest version" tab of a node.
WorkbenchPreprocess::preprocessNode public function Wrapper for hook_preprocess_HOOK().
WorkbenchPreprocess::__construct public function Constructor.