本文整理汇总了PHP中Drupal\Core\Theme\ThemeManagerInterface::getActiveTheme方法的典型用法代码示例。如果您正苦于以下问题:PHP ThemeManagerInterface::getActiveTheme方法的具体用法?PHP ThemeManagerInterface::getActiveTheme怎么用?PHP ThemeManagerInterface::getActiveTheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Theme\ThemeManagerInterface
的用法示例。
在下文中一共展示了ThemeManagerInterface::getActiveTheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getVisibleBlocksPerRegion
/**
* {@inheritdoc}
*/
public function getVisibleBlocksPerRegion(array &$cacheable_metadata = [])
{
$active_theme = $this->themeManager->getActiveTheme();
// Build an array of the region names in the right order.
$empty = array_fill_keys($active_theme->getRegions(), array());
$full = array();
foreach ($this->blockStorage->loadByProperties(array('theme' => $active_theme->getName())) as $block_id => $block) {
/** @var \Drupal\block\BlockInterface $block */
$access = $block->access('view', NULL, TRUE);
$region = $block->getRegion();
if (!isset($cacheable_metadata[$region])) {
$cacheable_metadata[$region] = CacheableMetadata::createFromObject($access);
} else {
$cacheable_metadata[$region] = $cacheable_metadata[$region]->merge(CacheableMetadata::createFromObject($access));
}
// Set the contexts on the block before checking access.
if ($access->isAllowed()) {
$full[$region][$block_id] = $block;
}
}
// Merge it with the actual values to maintain the region ordering.
$assignments = array_intersect_key(array_merge($empty, $full), $empty);
foreach ($assignments as &$assignment) {
// Suppress errors because PHPUnit will indirectly modify the contents,
// triggering https://bugs.php.net/bug.php?id=50688.
@uasort($assignment, 'Drupal\\block\\Entity\\Block::sort');
}
return $assignments;
}
示例2: getCid
/**
* {@inheritdoc}
*/
protected function getCid()
{
if (!isset($this->cid)) {
$this->cid = 'library_info:' . $this->themeManager->getActiveTheme()->getName();
}
return $this->cid;
}
示例3: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
$activeTheme = $this->themeManager->getActiveTheme();
$this->data['activeTheme'] = ['name' => $activeTheme->getName(), 'path' => $activeTheme->getPath(), 'engine' => $activeTheme->getEngine(), 'owner' => $activeTheme->getOwner(), 'baseThemes' => $activeTheme->getBaseThemes(), 'extension' => $activeTheme->getExtension(), 'styleSheetsRemove' => $activeTheme->getStyleSheetsRemove(), 'libraries' => $activeTheme->getLibraries(), 'regions' => $activeTheme->getRegions()];
if ($this->themeNegotiator instanceof ThemeNegotiatorWrapper) {
$this->data['negotiator'] = ['class' => $this->getMethodData($this->themeNegotiator->getNegotiator(), 'determineActiveTheme'), 'id' => $this->themeNegotiator->getNegotiator()->_serviceId];
}
}
示例4: testWildWest
/**
* Tests opting out of Stable by setting the base theme to false.
*/
public function testWildWest()
{
$this->themeHandler->install(['test_wild_west']);
$this->config('system.theme')->set('default', 'test_wild_west')->save();
$theme = $this->themeManager->getActiveTheme();
/** @var \Drupal\Core\Theme\ActiveTheme $base_theme */
$base_themes = $theme->getBaseThemes();
$this->assertTrue(empty($base_themes), 'No base theme is set when a theme has opted out of using Stable.');
}
示例5: getInfo
/**
* {@inheritdoc}
*/
public function getInfo($type)
{
$theme_name = $this->themeManager->getActiveTheme()->getName();
if (!isset($this->elementInfo[$theme_name])) {
$this->elementInfo[$theme_name] = $this->buildInfo($theme_name);
}
$info = isset($this->elementInfo[$theme_name][$type]) ? $this->elementInfo[$theme_name][$type] : array();
$info['#defaults_loaded'] = TRUE;
return $info;
}
示例6: testChanges
/**
* Tests that changes to the info file are picked up.
*/
public function testChanges()
{
$this->themeHandler->install(array('test_theme'));
$this->themeHandler->setDefault('test_theme');
$this->themeManager->resetActiveTheme();
$active_theme = $this->themeManager->getActiveTheme();
// Make sure we are not testing the wrong theme.
$this->assertEqual('test_theme', $active_theme->getName());
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
// @see theme_test_system_info_alter()
$this->state->set('theme_test.modify_info_files', TRUE);
drupal_flush_all_caches();
$active_theme = $this->themeManager->getActiveTheme();
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
}
示例7: evaluate
/**
* {@inheritdoc}
*/
public function evaluate()
{
if (!$this->configuration['theme']) {
return TRUE;
}
return $this->themeManager->getActiveTheme()->getName() == $this->configuration['theme'];
}
示例8: getThemeName
/**
* Gets the name of the theme used for this block listing.
*
* @return string
* The name of the theme.
*/
protected function getThemeName()
{
// If no theme was specified, use the current theme.
if (!$this->theme) {
$this->theme = $this->themeManager->getActiveTheme()->getName();
}
return $this->theme;
}
示例9: themePage
/**
* Page callback: Tests the theme negotiation functionality.
*
* @param bool $inherited
* TRUE when the requested page is intended to inherit
* the theme of its parent.
*
* @return string
* A string describing the requested custom theme and actual
* theme being used
* for the current page request.
*/
public function themePage($inherited)
{
$theme_key = $this->themeManager->getActiveTheme()->getName();
// Now we check what the theme negotiator service returns.
$active_theme = $this->themeNegotiator->determineActiveTheme($this->routeMatch);
$output = "Active theme: {$active_theme}. Actual theme: {$theme_key}.";
if ($inherited) {
$output .= ' Theme negotiation inheritance is being tested.';
}
return ['#markup' => $output];
}
示例10: build
/**
* {@inheritdoc}
*/
public function build()
{
$build = parent::build();
$active_theme = $this->themeManager->getActiveTheme();
$theme_name = $active_theme->getName();
$destination = $this->redirectDestination->get();
$visible_regions = $this->getVisibleRegionNames($theme_name);
// Build an array of the region names in the right order.
$build += array_fill_keys(array_keys($visible_regions), []);
foreach ($visible_regions as $region => $region_name) {
$query = ['region' => $region];
if ($destination) {
$query['destination'] = $destination;
}
$title = $this->t('<span class="visually-hidden">Place block in the %region region</span>', ['%region' => $region_name]);
$operations['block_description'] = ['#type' => 'inline_template', '#template' => '<div class="block-place-region">{{ link }}</div>', '#context' => ['link' => Link::createFromRoute($title, 'block.admin_library', ['theme' => $theme_name], ['query' => $query, 'attributes' => ['title' => $title, 'class' => ['use-ajax', 'button', 'button--small'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]])]];
$build[$region] = ['block_place_operations' => $operations] + $build[$region];
}
$build['#attached']['library'][] = 'block_place/drupal.block_place';
return $build;
}
示例11: applyLibrariesOverride
/**
* Apply libraries overrides specified for the current active theme.
*
* @param array $libraries
* The libraries definitions.
* @param string $extension
* The extension in which these libraries are defined.
*
* @return array
* The modified libraries definitions.
*/
protected function applyLibrariesOverride($libraries, $extension)
{
$active_theme = $this->themeManager->getActiveTheme();
// ActiveTheme::getLibrariesOverride() returns libraries-overrides for the
// current theme as well as all its base themes.
$all_libraries_overrides = $active_theme->getLibrariesOverride();
foreach ($all_libraries_overrides as $theme_path => $libraries_overrides) {
foreach ($libraries as $library_name => $library) {
// Process libraries overrides.
if (isset($libraries_overrides["{$extension}/{$library_name}"])) {
// Active theme defines an override for this library.
$override_definition = $libraries_overrides["{$extension}/{$library_name}"];
if (is_string($override_definition) || $override_definition === FALSE) {
// A string or boolean definition implies an override (or removal)
// for the whole library. Use the override key to specify that this
// library will be overridden when it is called.
// @see \Drupal\Core\Asset\LibraryDiscovery::getLibraryByName()
if ($override_definition) {
$libraries[$library_name]['override'] = $override_definition;
} else {
$libraries[$library_name]['override'] = FALSE;
}
} elseif (is_array($override_definition)) {
// An array definition implies an override for an asset within this
// library.
foreach ($override_definition as $sub_key => $value) {
// Throw an exception if the asset is not properly specified.
if (!is_array($value)) {
throw new InvalidLibrariesOverrideSpecificationException(sprintf('Library asset %s is not correctly specified. It should be in the form "extension/library_name/sub_key/path/to/asset.js".', "{$extension}/{$library_name}/{$sub_key}"));
}
if ($sub_key === 'drupalSettings') {
// drupalSettings may not be overridden.
throw new InvalidLibrariesOverrideSpecificationException(sprintf('drupalSettings may not be overridden in libraries-override. Trying to override %s. Use hook_library_info_alter() instead.', "{$extension}/{$library_name}/{$sub_key}"));
} elseif ($sub_key === 'css') {
// SMACSS category should be incorporated into the asset name.
foreach ($value as $category => $overrides) {
$this->setOverrideValue($libraries[$library_name], [$sub_key, $category], $overrides, $theme_path);
}
} else {
$this->setOverrideValue($libraries[$library_name], [$sub_key], $value, $theme_path);
}
}
}
}
}
}
return $libraries;
}
示例12: getCssAssets
/**
* {@inheritdoc}
*/
public function getCssAssets(AttachedAssetsInterface $assets, $optimize)
{
$theme_info = $this->themeManager->getActiveTheme();
$css = [];
$default_options = ['type' => 'file', 'group' => CSS_AGGREGATE_DEFAULT, 'weight' => 0, 'every_page' => FALSE, 'media' => 'all', 'preprocess' => TRUE, 'browsers' => []];
foreach ($this->getLibrariesToLoad($assets) as $library) {
list($extension, $name) = explode('/', $library, 2);
$definition = $this->libraryDiscovery->getLibraryByName($extension, $name);
if (isset($definition['css'])) {
foreach ($definition['css'] as $options) {
$options += $default_options;
$options['browsers'] += ['IE' => TRUE, '!IE' => TRUE];
// Files with a query string cannot be preprocessed.
if ($options['type'] === 'file' && $options['preprocess'] && strpos($options['data'], '?') !== FALSE) {
$options['preprocess'] = FALSE;
}
// Always add a tiny value to the weight, to conserve the insertion
// order.
$options['weight'] += count($css) / 1000;
// CSS files are being keyed by the full path.
$css[$options['data']] = $options;
}
}
}
// Allow modules and themes to alter the CSS assets.
$this->moduleHandler->alter('css', $css, $assets);
$this->themeManager->alter('css', $css, $assets);
// Sort CSS items, so that they appear in the correct order.
uasort($css, 'static::sort');
// Allow themes to remove CSS files by CSS files full path and file name.
if ($stylesheet_remove = $theme_info->getStyleSheetsRemove()) {
foreach ($css as $key => $options) {
if (isset($stylesheet_remove[$key])) {
unset($css[$key]);
}
}
}
if ($optimize) {
$css = \Drupal::service('asset.css.collection_optimizer')->optimize($css);
}
return $css;
}
示例13: applyLibrariesExtend
/**
* Applies the libraries-extend specified by the active theme.
*
* This extends the library definitions with the those specified by the
* libraries-extend specifications for the active theme.
*
* @param string $extension
* The name of the extension for which library definitions will be extended.
* @param string $library_name
* The name of the library whose definitions is to be extended.
* @param $library_definition
* The library definition to be extended.
*
* @return array
* The library definition extended as specified by libraries-extend.
*
* @throws \Drupal\Core\Asset\Exception\InvalidLibrariesExtendSpecificationException
*/
protected function applyLibrariesExtend($extension, $library_name, $library_definition)
{
$libraries_extend = $this->themeManager->getActiveTheme()->getLibrariesExtend();
if (!empty($libraries_extend["{$extension}/{$library_name}"])) {
foreach ($libraries_extend["{$extension}/{$library_name}"] as $library_extend_name) {
if (!is_string($library_extend_name)) {
// Only string library names are allowed.
throw new InvalidLibrariesExtendSpecificationException('The libraries-extend specification for each library must be a list of strings.');
}
list($new_extension, $new_library_name) = explode('/', $library_extend_name, 2);
$new_libraries = $this->get($new_extension);
if (isset($new_libraries[$new_library_name])) {
$library_definition = NestedArray::mergeDeep($library_definition, $new_libraries[$new_library_name]);
} else {
throw new InvalidLibrariesExtendSpecificationException(sprintf('The specified library "%s" does not exist.', $library_extend_name));
}
}
}
return $library_definition;
}
示例14: getMailTheme
/**
* Retrieves the key of the theme used to render the emails.
*/
public function getMailTheme()
{
$theme = $this->mailsystemConfig->get('theme');
switch ($theme) {
case 'default':
$theme = $this->configFactory->get('system.theme')->get('default');
break;
case 'current':
$theme = $this->themeManager->getActiveTheme()->getName();
break;
case 'domain':
// Fetch the theme for the current domain.
// @todo: Reimplement this as soon as module port or similar module is around.
if (FALSE && \Drupal::moduleHandler()->moduleExists('domain_theme')) {
// Assign the selected theme, based on the active domain.
global $_domain;
$domain_theme = domain_theme_lookup($_domain['domain_id']);
// The above returns -1 on failure.
$theme = $domain_theme != -1 ? $domain_theme['theme'] : $this->themeManager->getActiveTheme()->getName();
}
break;
}
return $theme;
}
示例15: getTheme
/**
* Gets the current theme for this page.
*
* @return string
* The current theme.
*/
protected function getTheme()
{
return $this->themeManager->getActiveTheme()->getName();
}