Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form['theme'] = array('#type' => 'select', '#title' => $this->t('Theme'), '#default_value' => $this->configuration['theme'], '#options' => array_map(function ($theme_info) {
         return $theme_info->info['name'];
     }, $this->themeHandler->listInfo()));
     return parent::buildConfigurationForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $config = $this->config('views.settings');
     $options = array();
     foreach ($this->themeHandler->listInfo() as $name => $theme) {
         if ($theme->status) {
             $options[$name] = $theme->info['name'];
         }
     }
     // This is not currently a fieldset but we may want it to be later,
     // so this will make it easier to change if we do.
     $form['basic'] = array();
     $form['basic']['ui_show_master_display'] = array('#type' => 'checkbox', '#title' => $this->t('Always show the master (default) display'), '#default_value' => $config->get('ui.show.master_display'));
     $form['basic']['ui_show_advanced_column'] = array('#type' => 'checkbox', '#title' => $this->t('Always show advanced display settings'), '#default_value' => $config->get('ui.show.advanced_column'));
     $form['basic']['ui_show_display_embed'] = array('#type' => 'checkbox', '#title' => t('Allow embedded displays'), '#description' => t('Embedded displays can be used in code via views_embed_view().'), '#default_value' => $config->get('ui.show.display_embed'));
     $form['basic']['ui_exposed_filter_any_label'] = array('#type' => 'select', '#title' => $this->t('Label for "Any" value on non-required single-select exposed filters'), '#options' => array('old_any' => '<Any>', 'new_any' => $this->t('- Any -')), '#default_value' => $config->get('ui.exposed_filter_any_label'));
     $form['live_preview'] = array('#type' => 'details', '#title' => $this->t('Live preview settings'), '#open' => TRUE);
     $form['live_preview']['ui_always_live_preview'] = array('#type' => 'checkbox', '#title' => $this->t('Automatically update preview on changes'), '#default_value' => $config->get('ui.always_live_preview'));
     $form['live_preview']['ui_show_preview_information'] = array('#type' => 'checkbox', '#title' => $this->t('Show information and statistics about the view during live preview'), '#default_value' => $config->get('ui.show.preview_information'));
     $form['live_preview']['options'] = array('#type' => 'container', '#states' => array('visible' => array(':input[name="ui_show_preview_information"]' => array('checked' => TRUE))));
     $form['live_preview']['options']['ui_show_sql_query_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Show the SQL query'), '#default_value' => $config->get('ui.show.sql_query.enabled'));
     $form['live_preview']['options']['ui_show_sql_query_where'] = array('#type' => 'radios', '#states' => array('visible' => array(':input[name="ui_show_sql_query_enabled"]' => array('checked' => TRUE))), '#title' => t('Show SQL query'), '#options' => array('above' => $this->t('Above the preview'), 'below' => $this->t('Below the preview')), '#default_value' => $config->get('ui.show.sql_query.where'));
     $form['live_preview']['options']['ui_show_performance_statistics'] = array('#type' => 'checkbox', '#title' => $this->t('Show performance statistics'), '#default_value' => $config->get('ui.show.performance_statistics'));
     $form['live_preview']['options']['ui_show_additional_queries'] = array('#type' => 'checkbox', '#title' => $this->t('Show other queries run during render during live preview'), '#description' => $this->t("Drupal has the potential to run many queries while a view is being rendered. Checking this box will display every query run during view render as part of the live preview."), '#default_value' => $config->get('ui.show.additional_queries'));
     return $form;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function getExtensions()
 {
     foreach ($this->moduleHandler->getModuleList() as $module) {
         (yield $this->wrapCoreExtension($module));
     }
     foreach ($this->themeHandler->listInfo() as $theme) {
         (yield $this->wrapCoreExtension($theme));
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $modules = $this->moduleHandler->getModuleList();
     $themes = $this->themeHandler->listInfo();
     $this->data['drupal_extension']['count'] = count($modules) + count($themes);
     $this->data['drupal_extension']['modules'] = $modules;
     $this->data['drupal_extension']['themes'] = $themes;
     $this->data['drupal_extension']['installation_path'] = $this->root . '/';
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
         if ($theme->status) {
             $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);
         }
     }
     return $this->derivatives;
 }
Пример #6
0
 /**
  * Theme constructor.
  *
  * @param \Drupal\Core\Extension\Extension $theme
  *   A theme \Drupal\Core\Extension\Extension object.
  * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
  *   The theme handler object.
  */
 public function __construct(Extension $theme, ThemeHandlerInterface $theme_handler)
 {
     $name = $theme->getName();
     $this->theme = $theme;
     $this->themeHandler = $theme_handler;
     $this->themes = $this->themeHandler->listInfo();
     $this->info = isset($this->themes[$name]->info) ? $this->themes[$name]->info : [];
     // Only install the theme if there is no schema version currently set.
     if (!$this->getSetting('schema')) {
         $this->install();
     }
 }
Пример #7
0
 /**
  * Invalidate the 'rendered' cache tag whenever a theme setting is modified.
  *
  * @param \Drupal\Core\Config\ConfigCrudEvent $event
  *   The Event to process.
  */
 public function onSave(ConfigCrudEvent $event)
 {
     // Global theme settings.
     if ($event->getConfig()->getName() === 'system.theme.global') {
         $this->cacheTagsInvalidator->invalidateTags(['rendered']);
     }
     // Theme-specific settings, check if this matches a theme settings
     // configuration object, in that case, clear the rendered cache tag.
     foreach (array_keys($this->themeHandler->listInfo()) as $theme_name) {
         if ($theme_name == $event->getConfig()->getName()) {
             $this->cacheTagsInvalidator->invalidateTags(['rendered']);
             break;
         }
     }
 }
 /**
  * Gets all extensions.
  *
  * @return array
  */
 protected function getExtensions()
 {
     if (!isset($this->extensions)) {
         $this->extensions = array_merge($this->moduleHandler->getModuleList(), $this->themeHandler->listInfo());
     }
     return $this->extensions;
 }
Пример #9
0
 /**
  * Set the default theme.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   A request object containing a theme name.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   Redirects back to the appearance admin page.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   Throws access denied when no theme is set in the request.
  */
 public function setDefaultTheme(Request $request)
 {
     $config = $this->configFactory->getEditable('system.theme');
     $theme = $request->query->get('theme');
     if (isset($theme)) {
         // Get current list of themes.
         $themes = $this->themeHandler->listInfo();
         // Check if the specified theme is one recognized by the system.
         // Or try to install the theme.
         if (isset($themes[$theme]) || $this->themeHandler->install(array($theme))) {
             $themes = $this->themeHandler->listInfo();
             // Set the default theme.
             $config->set('default', $theme)->save();
             $this->routeBuilder->setRebuildNeeded();
             // The status message depends on whether an admin theme is currently in
             // use: a value of 0 means the admin theme is set to be the default
             // theme.
             $admin_theme = $config->get('admin');
             if ($admin_theme != 0 && $admin_theme != $theme) {
                 drupal_set_message($this->t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array('%admin_theme' => $themes[$admin_theme]->info['name'], '%selected_theme' => $themes[$theme]->info['name'])));
             } else {
                 drupal_set_message($this->t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
             }
         } else {
             drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
         }
         return $this->redirect('system.themes_page');
     }
     throw new AccessDeniedHttpException();
 }
Пример #10
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  */
 public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
 {
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like twig_drupal_escape_filter are called.
     require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine';
     // Set twig path namespace for themes and modules.
     $namespaces = array();
     foreach ($module_handler->getModuleList() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($theme_handler->listInfo() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($namespaces as $name => $path) {
         $templatesDirectory = $path . '/templates';
         if (file_exists($templatesDirectory)) {
             $loader->addPath($templatesDirectory, $name);
         }
     }
     $this->templateClasses = array();
     $this->stringLoader = new \Twig_Loader_String();
     parent::__construct($loader, $options);
 }
Пример #11
0
 /**
  * Get the path to a theme.
  *
  * @param string $theme
  *   The machine name of the theme to get the path for.
  *
  * @return string
  *   The path to the given theme.
  *
  * @todo replace this with an injectable version of drupal_get_path() when/if
  *  it lands.
  */
 protected function getThemePath($theme)
 {
     $info = $this->themeHandler->listInfo();
     $path = '';
     if (isset($info[$theme])) {
         $path = dirname($info[$theme]->uri);
     }
     return $path;
 }
Пример #12
0
 /**
  * Presents the custom block creation form.
  *
  * @param \Drupal\block_content\BlockContentTypeInterface $block_content_type
  *   The custom block type to add.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  *
  * @return array
  *   A form array as expected by drupal_render().
  */
 public function addForm(BlockContentTypeInterface $block_content_type, Request $request)
 {
     $block = $this->blockContentStorage->create(array('type' => $block_content_type->id()));
     if (($theme = $request->query->get('theme')) && in_array($theme, array_keys($this->themeHandler->listInfo()))) {
         // We have navigated to this page from the block library and will keep track
         // of the theme for redirecting the user to the configuration page for the
         // newly created block in the given theme.
         $block->setTheme($theme);
     }
     return $this->entityFormBuilder()->getForm($block);
 }
Пример #13
0
 /**
  * {@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;
 }
Пример #14
0
 /**
  * Invalidate cache tags when particular system config objects are saved.
  *
  * @param \Drupal\Core\Config\ConfigCrudEvent $event
  *   The Event to process.
  */
 public function onSave(ConfigCrudEvent $event)
 {
     // Changing the site settings may mean a different route is selected for the
     // front page. Additionally a change to the site name or similar must
     // invalidate the render cache since this could be used anywhere.
     if ($event->getConfig()->getName() === 'system.site') {
         $this->cacheTagsInvalidator->invalidateTags(['route_match', 'rendered']);
     }
     // Theme configuration and global theme settings.
     if (in_array($event->getConfig()->getName(), ['system.theme', 'system.theme.global'], TRUE)) {
         $this->cacheTagsInvalidator->invalidateTags(['rendered']);
     }
     // Theme-specific settings, check if this matches a theme settings
     // configuration object, in that case, clear the rendered cache tag.
     foreach (array_keys($this->themeHandler->listInfo()) as $theme_name) {
         if ($theme_name == $event->getConfig()->getName()) {
             $this->cacheTagsInvalidator->invalidateTags(['rendered']);
             break;
         }
     }
 }
 /**
  * Returns a list with all themes.
  *
  * @return array
  *   Associative array with all enabled themes:
  *   - name: label
  */
 protected function getThemesList()
 {
     $theme_options = array('current' => $this->t('Current'), 'default' => $this->t('Default'));
     if ($this->moduleHandler->moduleExists('domain_theme')) {
         $theme_options['domain'] = $this->t('Domain Theme');
     }
     foreach ($this->themeHandler->listInfo() as $name => $theme) {
         if ($theme->status === 1) {
             $theme_options[$name] = $theme->info['name'];
         }
     }
     return $theme_options;
 }
 /**
  * {@inheritdoc}
  */
 public function getActiveThemeByName($theme_name)
 {
     if ($active_theme = $this->state->get('theme.active_theme.' . $theme_name)) {
         return $active_theme;
     }
     $themes = $this->themeHandler->listInfo();
     // If no theme could be negotiated, or if the negotiated theme is not within
     // the list of installed themes, fall back to the default theme output of
     // core and modules (like Stark, but without a theme extension at all). This
     // is possible, because loadActiveTheme() always loads the Twig theme
     // engine. This is desired, because missing or malformed theme configuration
     // should not leave the application in a broken state. By falling back to
     // default output, the user is able to reconfigure the theme through the UI.
     // Lastly, tests are expected to operate with no theme by default, so as to
     // only assert the original theme output of modules (unless a test manually
     // installs a specific theme).
     if (empty($themes) || !$theme_name || !isset($themes[$theme_name])) {
         $theme_name = 'core';
         // /core/core.info.yml does not actually exist, but is required because
         // Extension expects a pathname.
         $active_theme = $this->getActiveTheme(new Extension('theme', 'core/core.info.yml'));
         // Early-return and do not set state, because the initialized $theme_name
         // differs from the original $theme_name.
         return $active_theme;
     }
     // Find all our ancestor themes and put them in an array.
     $base_themes = array();
     $ancestor = $theme_name;
     while ($ancestor && isset($themes[$ancestor]->base_theme)) {
         $ancestor = $themes[$ancestor]->base_theme;
         $base_themes[] = $themes[$ancestor];
     }
     $active_theme = $this->getActiveTheme($themes[$theme_name], $base_themes);
     $this->state->set('theme.active_theme.' . $theme_name, $active_theme);
     return $active_theme;
 }
Пример #17
0
 /**
  * Constructs a new FilesystemLoader object.
  *
  * @param string|array $paths
  *   A path or an array of paths to check for templates.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler service.
  * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
  *   The theme handler service.
  */
 public function __construct($paths = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
 {
     parent::__construct($paths);
     // Add namespaced paths for modules and themes.
     $namespaces = array();
     foreach ($module_handler->getModuleList() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($theme_handler->listInfo() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($namespaces as $name => $path) {
         $this->addPath($path . '/templates', $name);
     }
 }
Пример #18
0
 /**
  * Theme constructor.
  *
  * @param \Drupal\Core\Extension\Extension $theme
  *   A theme \Drupal\Core\Extension\Extension object.
  * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
  *   The theme handler object.
  */
 public function __construct(Extension $theme, ThemeHandlerInterface $theme_handler)
 {
     $this->name = $theme->getName();
     $this->theme = $theme;
     $this->themeHandler = $theme_handler;
     $this->themes = $this->themeHandler->listInfo();
     $this->info = isset($this->themes[$this->name]->info) ? $this->themes[$this->name]->info : [];
     // Only install the theme if there is no schemas currently set.
     if (!$this->getSetting('schemas')) {
         try {
             $this->install();
         } catch (\Exception $e) {
             // Intentionally left blank.
             // @see https://www.drupal.org/node/2697075
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function findDefinitions()
 {
     $definitions = $this->getDiscovery()->getDefinitions();
     foreach ($definitions as $plugin_id => &$definition) {
         $this->processDefinition($definition, $plugin_id);
     }
     if ($this->alterHook) {
         $this->moduleHandler->alter($this->alterHook, $definitions);
     }
     // If this plugin was provided by a module that does not exist, remove the
     // plugin definition.
     foreach ($definitions as $plugin_id => $plugin_definition) {
         if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('core', 'component')) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
             unset($definitions[$plugin_id]);
         }
     }
     return $definitions;
 }
Пример #20
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  */
 public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
 {
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
     // Set twig path namespace for themes and modules.
     $namespaces = array();
     foreach ($module_handler->getModuleList() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($theme_handler->listInfo() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($namespaces as $name => $path) {
         $templatesDirectory = $path . '/templates';
         if (file_exists($templatesDirectory)) {
             $loader->addPath($templatesDirectory, $name);
         }
     }
     $this->templateClasses = array();
     parent::__construct($loader, $options);
 }
 /**
  * Gets all libraries for core and all installed modules.
  *
  * @return \Drupal\Core\Extension\Extension[]
  */
 protected function getAllLibraries()
 {
     $modules = \Drupal::moduleHandler()->getModuleList();
     $extensions = $modules;
     $module_list = array_keys($modules);
     sort($module_list);
     $this->assertEqual($this->allModules, $module_list, 'All core modules are installed.');
     $themes = $this->themeHandler->listInfo();
     $extensions += $themes;
     $theme_list = array_keys($themes);
     sort($theme_list);
     $this->assertEqual($this->allThemes, $theme_list, 'All core themes are installed.');
     $libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core');
     $root = \Drupal::root();
     foreach ($extensions as $extension_name => $extension) {
         $library_file = $extension->getPath() . '/' . $extension_name . '.libraries.yml';
         if (is_file($root . '/' . $library_file)) {
             $libraries[$extension_name] = $this->libraryDiscovery->getLibrariesByExtension($extension_name);
         }
     }
     return $libraries;
 }
Пример #22
0
 /**
  * {@inheritdoc}
  *
  * @param string $theme
  *   The theme name.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $theme = '')
 {
     $form = parent::buildForm($form, $form_state);
     $themes = $this->themeHandler->listInfo();
     // Default settings are defined in theme_get_setting() in includes/theme.inc
     if ($theme) {
         if (!$this->themeHandler->hasUi($theme)) {
             throw new NotFoundHttpException();
         }
         $var = 'theme_' . $theme . '_settings';
         $config_key = $theme . '.settings';
         $themes = $this->themeHandler->listInfo();
         $features = $themes[$theme]->info['features'];
     } else {
         $var = 'theme_settings';
         $config_key = 'system.theme.global';
     }
     // @todo this is pretty meaningless since we're using theme_get_settings
     //   which means overrides can bleed into active config here. Will be fixed
     //   by https://www.drupal.org/node/2402467.
     $this->editableConfig = [$config_key];
     $form['var'] = array('#type' => 'hidden', '#value' => $var);
     $form['config_key'] = array('#type' => 'hidden', '#value' => $config_key);
     // Toggle settings
     $toggles = array('node_user_picture' => t('User pictures in posts'), 'comment_user_picture' => t('User pictures in comments'), 'comment_user_verification' => t('User verification status in comments'), 'favicon' => t('Shortcut icon'));
     // Some features are not always available
     $disabled = array();
     if (!user_picture_enabled()) {
         $disabled['toggle_node_user_picture'] = TRUE;
         $disabled['toggle_comment_user_picture'] = TRUE;
     }
     if (!$this->moduleHandler->moduleExists('comment')) {
         $disabled['toggle_comment_user_picture'] = TRUE;
         $disabled['toggle_comment_user_verification'] = TRUE;
     }
     $form['theme_settings'] = array('#type' => 'details', '#title' => t('Toggle display'), '#open' => TRUE, '#description' => t('Enable or disable the display of certain page elements.'));
     foreach ($toggles as $name => $title) {
         if (!$theme || in_array($name, $features)) {
             $form['theme_settings']['toggle_' . $name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting('features.' . $name, $theme));
             // Disable checkboxes for features not supported in the current configuration.
             if (isset($disabled['toggle_' . $name])) {
                 $form['theme_settings']['toggle_' . $name]['#disabled'] = TRUE;
             }
         }
     }
     if (!Element::children($form['theme_settings'])) {
         // If there is no element in the theme settings details then do not show
         // it -- but keep it in the form if another module wants to alter.
         $form['theme_settings']['#access'] = FALSE;
     }
     // Logo settings, only available when file.module is enabled.
     if (!$theme || in_array('logo', $features) && $this->moduleHandler->moduleExists('file')) {
         $form['logo'] = array('#type' => 'details', '#title' => t('Logo image settings'), '#open' => TRUE, '#states' => array('invisible' => array('input[name="toggle_logo"]' => array('checked' => FALSE))));
         $form['logo']['default_logo'] = array('#type' => 'checkbox', '#title' => t('Use the default logo supplied by the theme'), '#default_value' => theme_get_setting('logo.use_default', $theme), '#tree' => FALSE);
         $form['logo']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_logo"]' => array('checked' => TRUE))));
         $form['logo']['settings']['logo_path'] = array('#type' => 'textfield', '#title' => t('Path to custom logo'), '#default_value' => theme_get_setting('logo.path', $theme));
         $form['logo']['settings']['logo_upload'] = array('#type' => 'file', '#title' => t('Upload logo image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."));
     }
     if ((!$theme || in_array('favicon', $features)) && $this->moduleHandler->moduleExists('file')) {
         $form['favicon'] = array('#type' => 'details', '#title' => t('Shortcut icon settings'), '#open' => TRUE, '#description' => t("Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers."), '#states' => array('invisible' => array('input[name="toggle_favicon"]' => array('checked' => FALSE))));
         $form['favicon']['default_favicon'] = array('#type' => 'checkbox', '#title' => t('Use the default shortcut icon supplied by the theme'), '#default_value' => theme_get_setting('favicon.use_default', $theme));
         $form['favicon']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_favicon"]' => array('checked' => TRUE))));
         $form['favicon']['settings']['favicon_path'] = array('#type' => 'textfield', '#title' => t('Path to custom icon'), '#default_value' => theme_get_setting('favicon.path', $theme));
         $form['favicon']['settings']['favicon_upload'] = array('#type' => 'file', '#title' => t('Upload icon image'), '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
     }
     // Inject human-friendly values and form element descriptions for logo and
     // favicon.
     foreach (array('logo' => 'logo.svg', 'favicon' => 'favicon.ico') as $type => $default) {
         if (isset($form[$type]['settings'][$type . '_path'])) {
             $element =& $form[$type]['settings'][$type . '_path'];
             // If path is a public:// URI, display the path relative to the files
             // directory; stream wrappers are not end-user friendly.
             $original_path = $element['#default_value'];
             $friendly_path = NULL;
             if (file_uri_scheme($original_path) == 'public') {
                 $friendly_path = file_uri_target($original_path);
                 $element['#default_value'] = $friendly_path;
             }
             // Prepare local file path for description.
             if ($original_path && isset($friendly_path)) {
                 $local_file = strtr($original_path, array('public:/' => PublicStream::basePath()));
             } elseif ($theme) {
                 $local_file = drupal_get_path('theme', $theme) . '/' . $default;
             } else {
                 $local_file = \Drupal::theme()->getActiveTheme()->getPath() . '/' . $default;
             }
             $element['#description'] = t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', array('@implicit-public-file' => isset($friendly_path) ? $friendly_path : $default, '@explicit-file' => file_uri_scheme($original_path) !== FALSE ? $original_path : 'public://' . $default, '@local-file' => $local_file));
         }
     }
     if ($theme) {
         // Call engine-specific settings.
         $function = $themes[$theme]->prefix . '_engine_settings';
         if (function_exists($function)) {
             $form['engine_specific'] = array('#type' => 'details', '#title' => t('Theme-engine-specific settings'), '#open' => TRUE, '#description' => t('These settings only exist for the themes based on the %engine theme engine.', array('%engine' => $themes[$theme]->prefix)));
             $function($form, $form_state);
         }
         // Create a list which includes the current theme and all its base themes.
         if (isset($themes[$theme]->base_themes)) {
             $theme_keys = array_keys($themes[$theme]->base_themes);
             $theme_keys[] = $theme;
         } else {
             $theme_keys = array($theme);
         }
         // Save the name of the current theme (if any), so that we can temporarily
         // override the current theme and allow theme_get_setting() to work
         // without having to pass the theme name to it.
         $default_active_theme = \Drupal::theme()->getActiveTheme();
         $default_theme = $default_active_theme->getName();
         /** @var \Drupal\Core\Theme\ThemeInitialization $theme_initialization */
         $theme_initialization = \Drupal::service('theme.initialization');
         \Drupal::theme()->setActiveTheme($theme_initialization->getActiveThemeByName($theme));
         // Process the theme and all its base themes.
         foreach ($theme_keys as $theme) {
             // Include the theme-settings.php file.
             $filename = DRUPAL_ROOT . '/' . $themes[$theme]->getPath() . '/theme-settings.php';
             if (file_exists($filename)) {
                 require_once $filename;
             }
             // Call theme-specific settings.
             $function = $theme . '_form_system_theme_settings_alter';
             if (function_exists($function)) {
                 $function($form, $form_state);
             }
         }
         // Restore the original current theme.
         if (isset($default_theme)) {
             \Drupal::theme()->setActiveTheme($default_active_theme);
         } else {
             \Drupal::theme()->resetActiveTheme();
         }
     }
     return $form;
 }
Пример #23
0
 /**
  * Generates a report about config updates.
  *
  * @param string $report_type
  *   Type of report to generate: 'type', 'module', 'theme', or 'profile'.
  * @param string $value
  *   Machine name of a configuration type, module, or theme to generate the
  *   report for. Ignored for profile, since that uses the active profile.
  *
  * @return array
  *   Render array for the updates report. Empty if invalid or missing
  *   report type or value.
  */
 protected function generateReport($report_type, $value)
 {
     // Figure out what to name the report, and incidentally, validate that
     // $value exists for this type of report.
     switch ($report_type) {
         case 'type':
             if ($value == 'system.all') {
                 $label = $this->t('All configuration');
             } elseif ($value == 'system.simple') {
                 $label = $this->t('Simple configuration');
             } else {
                 $definition = $this->configList->getType($value);
                 if (!$definition) {
                     return NULL;
                 }
                 $label = $this->t('@name configuration', array('@name' => $definition->getLabel()));
             }
             break;
         case 'module':
             $list = $this->moduleHandler->getModuleList();
             if (!isset($list[$value])) {
                 return NULL;
             }
             $label = $this->t('@name module', array('@name' => $this->moduleHandler->getName($value)));
             break;
         case 'theme':
             $list = $this->themeHandler->listInfo();
             if (!isset($list[$value])) {
                 return NULL;
             }
             $label = $this->t('@name theme', array('@name' => $this->themeHandler->getName($value)));
             break;
         case 'profile':
             $profile = Settings::get('install_profile');
             $label = $this->t('@name profile', array('@name' => $this->moduleHandler->getName($profile)));
             break;
         default:
             return NULL;
     }
     // List the active and extension-provided config.
     list($active_list, $install_list, $optional_list) = $this->configList->listConfig($report_type, $value);
     // Build the report.
     $build = array();
     $build['#title'] = $this->t('Configuration updates report for @label', array('@label' => $label));
     $build['report_header'] = array('#markup' => '<h3>' . $this->t('Updates report') . '</h3>');
     // List items missing from site.
     $removed = array_diff($install_list, $active_list);
     $build['removed'] = array('#caption' => $this->t('Missing configuration items'), '#empty' => $this->t('None: all provided configuration items are in your active configuration.')) + $this->makeReportTable($removed, 'extension', array('import'));
     // List optional items that are not installed.
     $inactive = array_diff($optional_list, $active_list);
     $build['inactive'] = array('#caption' => $this->t('Inactive optional items'), '#empty' => $this->t('None: all optional configuration items are in your active configuration.')) + $this->makeReportTable($inactive, 'extension', array('import'));
     // List items added to site, which only makes sense in the report for a
     // config type.
     $added = array_diff($active_list, $install_list, $optional_list);
     if ($report_type == 'type') {
         $build['added'] = array('#caption' => $this->t('Added configuration items'), '#empty' => $this->t('None: all active configuration items of this type were provided by modules, themes, or install profile.')) + $this->makeReportTable($added, 'active', array('export', 'delete'));
     }
     // For differences, we need to go through the array of config in both
     // and see if each config item is the same or not.
     $both = array_diff($active_list, $added);
     $different = array();
     foreach ($both as $name) {
         if (!$this->configDiff->same($this->configRevert->getFromExtension('', $name), $this->configRevert->getFromActive('', $name))) {
             $different[] = $name;
         }
     }
     $build['different'] = array('#caption' => $this->t('Changed configuration items'), '#empty' => $this->t('None: no active configuration items differ from their current provided versions.')) + $this->makeReportTable($different, 'active', array('diff', 'export', 'revert'));
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeHandlerInterface $theme_handler)
 {
     parent::__construct($entity_type, $storage);
     $this->themes = $theme_handler->listInfo();
 }
Пример #25
0
 /**
  * Indicates whether the theme is accessible based on whether it is installed.
  *
  * @param string $theme
  *   The name of a theme.
  *
  * @return bool
  *   TRUE if the theme is installed, FALSE otherwise.
  */
 public function checkAccess($theme)
 {
     $themes = $this->themeHandler->listInfo();
     return !empty($themes[$theme]->status);
 }