44
55use Drupal \Core \Access \AccessResult ;
66use Drupal \Core \Controller \ControllerBase ;
7- use Drupal \Component \Utility \Xss ;
87use Symfony \Component \DependencyInjection \ContainerInterface ;
9- use Twig \Error \LoaderError ;
108
119/**
1210 * Creates style guide at /styleguide.
1311 */
1412class StyleGuideController extends ControllerBase {
1513
1614 /**
17- * The theme manager .
15+ * The Library discovery service .
1816 *
19- * @var \Drupal\Core\Theme\ThemeManagerInterface
17+ * @var \Drupal\Core\Asset\LibraryDiscoveryCollector
2018 */
21- protected $ themeManager ;
19+ protected $ libraries ;
2220
2321 /**
24- * The twig service .
22+ * The theme manager .
2523 *
26- * @var \Drupal\Core\Template\TwigEnvironment
24+ * @var \Drupal\Core\Theme\ThemeManagerInterface
2725 */
28- protected $ twig ;
26+ protected $ themeManager ;
2927
3028 /**
3129 * {@inheritDoc}
3230 */
3331 public static function create (ContainerInterface $ container ) {
3432 $ instance = parent ::create ($ container );
3533 $ instance ->configFactory = $ container ->get ('config.factory ' );
34+ $ instance ->libraries = $ container ->get ('library.discovery ' );
3635 $ instance ->themeManager = $ container ->get ('theme.manager ' );
37- $ instance ->twig = $ container ->get ('twig ' );
3836 return $ instance ;
3937 }
4038
@@ -46,11 +44,14 @@ public static function create(ContainerInterface $container) {
4644 */
4745 public function tsStyleGuide () {
4846 $ themename = $ this ->configFactory ->get ('system.theme ' )->get ('default ' );
49-
50- return [
47+ $ content = [
5148 '#theme ' => 'styleguide ' ,
5249 '#theme_name ' => $ themename ,
5350 ];
51+ if ($ this ->libraries ->getLibraryByName ($ themename , 'ts_styleguide ' )) {
52+ $ content ['#attached ' ]['library ' ][] = "$ themename/ts_styleguide " ;
53+ }
54+ return $ content ;
5455 }
5556
5657 /**
0 commit comments