You are here

public function PageTitle::preprocess in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  2. 8 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  3. 8.3 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  4. 8.4 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  5. 8.5 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  6. 8.6 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  7. 8.7 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()
  8. 8.8 themes/socialbase/src/Plugin/Preprocess/PageTitle.php \Drupal\socialbase\Plugin\Preprocess\PageTitle::preprocess()

Preprocess theme hook variables.

Parameters

array $variables: The variables array, passed by reference (modify in place).

string $hook: The name of the theme hook.

array $info: The theme hook info array.

Overrides PreprocessBase::preprocess

File

themes/socialbase/src/Plugin/Preprocess/PageTitle.php, line 20

Class

PageTitle
Pre-processes variables for the "page_title" theme hook.

Namespace

Drupal\socialbase\Plugin\Preprocess

Code

public function preprocess(array &$variables, $hook, array $info) {
  parent::preprocess($variables, $hook, $info);

  // Get the current path and if is it stream return a variable.
  $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;
  }

  // Check if it is a node.
  if (strpos($current_path, 'node') !== FALSE) {
    $variables['node'] = TRUE;
  }

  // Check if it is the edit/add/delete.
  $paths_to_exclude = [
    'edit',
    'add',
    'delete',
  ];
  $in_path = str_replace($paths_to_exclude, '', $current_path) !== $current_path;
  if ($in_path) {
    $variables['edit'] = TRUE;
  }
}