You are here

function social_path_manager_preprocess_block in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  2. 8.6 modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  3. 8.7 modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  4. 8.8 modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  5. 10.0.x modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  6. 10.1.x modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()
  7. 10.2.x modules/custom/social_path_manager/social_path_manager.module \social_path_manager_preprocess_block()

Implements hook_preprocess_HOOK().

File

modules/custom/social_path_manager/social_path_manager.module, line 301
The Social Path Manager module.

Code

function social_path_manager_preprocess_block(&$variables) {

  /** @var \Drupal\node\Entity\Node $node */
  $node = \Drupal::routeMatch()
    ->getParameter('node');

  // Due to PR #1427 there are now two heroes shown on pages
  // with a certain url alias. Due to the refactor in socialpagetitleblock.
  if ($node !== NULL) {
    if (!empty($variables['elements']['#plugin_id']) && $variables['elements']['#plugin_id'] === 'social_page_title_block' && $variables['elements']['#id'] === 'socialblue_pagetitleblock_content') {
      $current_url = Url::fromRoute('<current>');
      $current_path = $current_url
        ->toString();
      $paths_to_exclude = [
        'edit',
        'add',
        'delete',
      ];
      $in_path = str_replace($paths_to_exclude, '', $current_path) !== $current_path;

      // We make sure there are no two heroes shown only page titles.
      if ($in_path) {
        $variables['content']['#type'] = 'page_title';
        if (!empty($variables['content']['#hero_node'])) {
          unset($variables['content']['#hero_node']);
        }
      }
    }
  }
}