/** * Inject the relevant css for the template. * * You can specify CSS files to be included per entity type and bundle in your * themes css file. This code uses your current theme which is likely to be the * front end theme. * * Examples: * * entity_print: * all: 'yourtheme/all-pdfs', * commerce_order: * all: 'yourtheme/orders' * node: * article: 'yourtheme/article-pdf' * * @param array $render * The renderable array. * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity info from entity_get_info(). * * @return array * An array of stylesheets to be used for this template. */ protected function addCss($render, ContentEntityInterface $entity) { $theme = $this->themeHandler->getDefault(); $theme_path = $this->getThemePath($theme); /** @var \Drupal\Core\Extension\InfoParser $parser */ $theme_info = $this->infoParser->parse("{$theme_path}/{$theme}.info.yml"); // Parse out the CSS from the theme info. if (isset($theme_info['entity_print'])) { // See if we have the special "all" key which is added to every PDF. if (isset($theme_info['entity_print']['all'])) { $render['#attached']['library'][] = $theme_info['entity_print']['all']; unset($theme_info['entity_print']['all']); } foreach ($theme_info['entity_print'] as $key => $value) { // If the entity type doesn't match just skip. if ($key !== $entity->getEntityTypeId()) { continue; } // Parse our css files per entity type and bundle. foreach ($value as $css_bundle => $css) { // If it's magic key "all" add it otherwise check the bundle. if ($css_bundle === 'all' || $entity->bundle() === $css_bundle) { $render['#attached']['library'][] = $css; } } } } return $render; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $default_theme = $this->themeHandler->getDefault(); foreach ($this->themeHandler->listInfo() as $theme_name => $theme) { if ($this->themeHandler->hasUi($theme_name)) { $this->derivatives[$theme_name] = $base_plugin_definition; $this->derivatives[$theme_name]['title'] = $theme->info['name']; $this->derivatives[$theme_name]['route_parameters'] = array('theme' => $theme_name); } // Default task! if ($default_theme == $theme_name) { $this->derivatives[$theme_name]['route_name'] = $base_plugin_definition['parent_id']; // Emulate default logic because without the base plugin id we can't // change the base_route. $this->derivatives[$theme_name]['weight'] = -10; unset($this->derivatives[$theme_name]['route_parameters']); } } return $this->derivatives; }
/** * Disables the language switcher blocks. * * @param array $language_types * An array containing all language types whose language switchers need to * be disabled. */ protected function disableLanguageSwitcher(array $language_types) { $theme = $this->themeHandler->getDefault(); $blocks = $this->blockStorage->loadByProperties(array('theme' => $theme)); foreach ($language_types as $language_type) { foreach ($blocks as $block) { if ($block->getPluginId() == 'language_block:' . $language_type) { $block->delete(); } } } }
/** * Disables the language switcher blocks. * * @param array $language_types * An array containing all language types whose language switchers need to * be disabled. */ protected function disableLanguageSwitcher(array $language_types) { $theme = $this->themeHandler->getDefault(); $blocks = $this->blockStorage->loadByProperties(array('theme' => $theme)); foreach ($language_types as $language_type) { foreach ($blocks as $block) { if (strpos($block->id, 'language_switcher_' . substr($language_type, 9)) !== FALSE) { $block->delete(); } } } }