PageTitle.php in Open Social 8.2
File
themes/socialbase/src/Plugin/Preprocess/PageTitle.php
View source
<?php
namespace Drupal\socialbase\Plugin\Preprocess;
use Drupal\bootstrap\Plugin\Preprocess\PreprocessBase;
use Drupal\Core\Url;
class PageTitle extends PreprocessBase {
public function preprocess(array &$variables, $hook, array $info) {
parent::preprocess($variables, $hook, $info);
$current_url = Url::fromRoute('<current>');
$current_path = $current_url
->toString();
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name === 'entity.profile.type.user_profile_form') {
$profile_type = $variables['title']
->getArguments();
if (!empty($profile_type['@label'])) {
$variables['title'] = t('Edit @label', [
'@label' => $profile_type['@label'],
]);
}
}
if ($route_name === 'entity.user.edit_form' && isset($variables['title']['#markup'])) {
$variables['title'] = t('<em>Configure account settings:</em> @label', [
'@label' => $variables['title']['#markup'],
]);
}
if (strpos($current_path, 'stream') !== FALSE || strpos($current_path, 'explore') !== FALSE) {
$variables['stream'] = TRUE;
}
if (strpos($current_path, 'node') !== FALSE) {
$variables['node'] = TRUE;
}
$paths_to_exclude = [
'edit',
'add',
'delete',
];
$in_path = str_replace($paths_to_exclude, '', $current_path) !== $current_path;
if ($in_path) {
$variables['edit'] = TRUE;
}
}
}
Classes
Name |
Description |
PageTitle |
Pre-processes variables for the "page_title" theme hook. |