本文整理汇总了PHP中Drupal\Core\Extension\ThemeHandlerInterface::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP ThemeHandlerInterface::getDefault方法的具体用法?PHP ThemeHandlerInterface::getDefault怎么用?PHP ThemeHandlerInterface::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Extension\ThemeHandlerInterface
的用法示例。
在下文中一共展示了ThemeHandlerInterface::getDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCss
/**
* 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;
}
示例2: getDerivativeDefinitions
/**
* {@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;
}
示例3: disableLanguageSwitcher
/**
* 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();
}
}
}
}
示例4: disableLanguageSwitcher
/**
* 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();
}
}
}
}