View title change based on context I have a view that lists nodes of a certain type "TypeA" using their titles (and a link to click on).
The view filters out the current TypeA node from that list using a contextual filter set to Content:ID with a default value passed in through the request URL, and the "Exclude" checkbox ticked.
Consequently, when the currently displayed node is not of TypeA, all nodes of TypeA are listed.

I want the block in which the view is displayed to change title depending on whether I view a node of TypeA or not, as follows:


Node is of TypeA, the title is set to "Other TypeAs"
Otherwise, the title is set to "All TypeAs"


I don't know how to further test the query result for the condition, or change the contextual filter (since I always have a Content:ID passed in) to make that happen.

One possible workaround could be to trigger on the URL path because all nodes of TypeA have a custom URL path (via the Pathauto module) configured.

I am using Drupal 8.4.6, soon to migrate to 8.5.
You can implement a hook in your module. Ex:

/**
 * Update title of block based on the node type currently being viewed.
 *
 * Implements hook_block_view_alter().
 */
function my_module_block_view_alter(&amp;$build, \Drupal\Core\Block\BlockPluginInterface $block) {
  // Only act on the block you want.
  if ($build['#id'] == 'your_block_id') {
    // Attempt to get the current node object from the route.
    $node = \Drupal::routeMatch()-&gt;getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      if ($node-&gt;getType() == 'type_a') {
        $build['#configuration']['label'] = t('Other Type As');
      }
      else {
        $build['#configuration']['label'] = t('All Type As');
      }
    }
  }
}


See api documentation for hook_block_view_alter for more info.