shortcut_preprocess_page_title(&$variables)
Implements hook_preprocess_HOOK() for page title templates.
File
- core/modules/shortcut/shortcut.module, line 303
- Allows users to manage customizable lists of shortcut links.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | function shortcut_preprocess_page_title(& $variables ) { // Only display the shortcut link if the user has the ability to edit // shortcuts and if the page's actual content is being shown (for example, // we do not want to display it on "access denied" or "page not found" // pages). if (shortcut_set_edit_access()->isAllowed() && !\Drupal::request()->attributes->has( 'exception' )) { $link = Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath(); $route_match = \Drupal::routeMatch(); // Replicate template_preprocess_html()'s processing to get the title in // string form, so we can set the default name for the shortcut. // Strip HTML tags from the title. $name = trim( strip_tags (render( $variables [ 'title' ]))); $query = array ( 'link' => $link , 'name' => $name , ); $shortcut_set = shortcut_current_displayed_set(); // Check if $link is already a shortcut and set $link_mode accordingly. $shortcuts = \Drupal::entityManager()->getStorage( 'shortcut' )->loadByProperties( array ( 'shortcut_set' => $shortcut_set ->id())); /** @var \Drupal\shortcut\ShortcutInterface $shortcut */ foreach ( $shortcuts as $shortcut ) { if (( $shortcut_url = $shortcut ->getUrl()) && $shortcut_url ->isRouted() && $shortcut_url ->getRouteName() == $route_match ->getRouteName() && $shortcut_url ->getRouteParameters() == $route_match ->getRawParameters()->all()) { $shortcut_id = $shortcut ->id(); break ; } } $link_mode = isset( $shortcut_id ) ? "remove" : "add" ; if ( $link_mode == "add" ) { $link_text = shortcut_set_switch_access()->isAllowed() ? t( 'Add to %shortcut_set shortcuts' , array ( '%shortcut_set' => $shortcut_set ->label())) : t( 'Add to shortcuts' ); $route_name = 'shortcut.link_add_inline' ; $route_parameters = array ( 'shortcut_set' => $shortcut_set ->id()); } else { $query [ 'id' ] = $shortcut_id ; $link_text = shortcut_set_switch_access()->isAllowed() ? t( 'Remove from %shortcut_set shortcuts' , array ( '%shortcut_set' => $shortcut_set ->label())) : t( 'Remove from shortcuts' ); $route_name = 'entity.shortcut.link_delete_inline' ; $route_parameters = array ( 'shortcut' => $shortcut_id ); } if (theme_get_setting( 'third_party_settings.shortcut.module_link' )) { $query += \Drupal::destination()->getAsArray(); $variables [ 'title_suffix' ][ 'add_or_remove_shortcut' ] = array ( '#attached' => array ( 'library' => array ( 'shortcut/drupal.shortcut' , ), ), '#type' => 'link' , '#title' => SafeMarkup::format( '<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>' , array ( '@text' => $link_text )), '#url' => Url::fromRoute( $route_name , $route_parameters ), '#options' => array ( 'query' => $query ), '#attributes' => array ( 'class' => array ( 'shortcut-action' , 'shortcut-action--' . $link_mode , ), ), ); } } } |
Please login to continue.