function SettingsTrayHooks::contextualLinksViewAlter

Implements hook_contextual_links_view_alter().

Change Configure Blocks into off_canvas links.

File

core/modules/settings_tray/src/Hook/SettingsTrayHooks.php, line 56

Class

SettingsTrayHooks
Hook implementations for settings_tray.

Namespace

Drupal\settings_tray\Hook

Code

public function contextualLinksViewAlter(&$element, $items) {
    if (isset($element['#links']['settings-trayblock-configure'])) {
        // Place settings_tray link first.
        $settings_tray_link = $element['#links']['settings-trayblock-configure'];
        unset($element['#links']['settings-trayblock-configure']);
        $element['#links'] = [
            'settings-trayblock-configure' => $settings_tray_link,
        ] + $element['#links'];
        // If this is content block change title to avoid duplicate "Quick Edit".
        if (isset($element['#links']['block-contentblock-edit'])) {
            $element['#links']['settings-trayblock-configure']['title'] = t('Quick edit settings');
        }
        $element['#attached']['library'][] = 'core/drupal.dialog.off_canvas';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.