Last active
April 4, 2019 13:56
-
-
Save mattschaff/132636fe9a6f3bed64e04904f568d7ae to your computer and use it in GitHub Desktop.
Drupal 8: Dynamically set page title of view page display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\views\ViewExecutable; | |
/** | |
* Implements hook_views_post_render(). | |
*/ | |
function my_module_views_post_render(ViewExecutable $view, &$output) { | |
if ($view->id() == 'view_machine_name') { | |
// Set title based on the user name of the current user profile. | |
// Note: This view is only set to display on the /user path. | |
$current_path = \Drupal::service('path.current')->getPath(); | |
$path_items = explode('/', $current_path); | |
$user = User::load($path_items[2]); | |
$view->setTitle($user->getAccountName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment