protected function themeDetail(DrupalStyle $io, $themeId) { $theme = null; $themes = $this->themeHandler->rebuildThemeData(); if (isset($themes[$themeId])) { $theme = $themes[$themeId]; } else { foreach ($themes as $themeAvailableId => $themeAvailable) { if ($themeAvailable->info['name'] == $themeId) { $themeId = $themeAvailableId; $theme = $themeAvailable; break; } } } if ($theme) { $theme = $themes[$themeId]; $status = $this->getThemeStatus($themeId); $io->info($theme->info['name']); $io->comment(sprintf('%s : ', $this->trans('commands.theme.debug.messages.status')), false); $io->writeln($status); $io->comment(sprintf('%s : ', $this->trans('commands.theme.debug.messages.version')), false); $io->writeln($theme->info['version']); $io->comment($this->trans('commands.theme.debug.messages.regions')); $tableRows = $this->addThemeAttributes($theme->info['regions'], $tableRows); $io->table([], $tableRows); } else { $io->error(sprintf($this->trans('commands.theme.debug.messages.invalid-theme'), $themeId)); } }
/** * 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()); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $entity = $this->entity; // Store theme settings in $form_state for use below. if (!($theme = $entity->getTheme())) { $theme = $this->config('system.theme')->get('default'); } $form_state->set('block_theme', $theme); // Store the gathered contexts in the form state for other objects to use // during form building. $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts()); $form['#tree'] = TRUE; $form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state); $form['visibility'] = $this->buildVisibilityInterface([], $form_state); // If creating a new block, calculate a safe default machine name. $form['id'] = array('#type' => 'machine_name', '#maxlength' => 64, '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'), '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array('exists' => '\\Drupal\\block\\Entity\\Block::load', 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label')), '#required' => TRUE, '#disabled' => !$entity->isNew()); // Theme settings. if ($entity->getTheme()) { $form['theme'] = array('#type' => 'value', '#value' => $theme); } else { $theme_options = array(); foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) { if (!empty($theme_info->status)) { $theme_options[$theme_name] = $theme_info->info['name']; } } $form['theme'] = array('#type' => 'select', '#options' => $theme_options, '#title' => t('Theme'), '#default_value' => $theme, '#ajax' => array('callback' => '::themeSwitch', 'wrapper' => 'edit-block-region-wrapper')); } // Region settings. $entity_region = $entity->getRegion(); $region = $entity->isNew() ? $this->getRequest()->query->get('region', $entity_region) : $entity_region; $form['region'] = array('#type' => 'select', '#title' => $this->t('Region'), '#description' => $this->t('Select the region where this block should be displayed.'), '#default_value' => $region, '#empty_value' => BlockInterface::BLOCK_REGION_NONE, '#options' => system_region_list($theme, REGIONS_VISIBLE), '#prefix' => '<div id="edit-block-region-wrapper">', '#suffix' => '</div>'); $form['#attached']['library'][] = 'block/drupal.block.admin'; return $form; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $config = $this->configFactory->getEditable('system.theme'); $this->themeHandler->refreshInfo(); $theme = $input->getArgument('theme'); $default = $input->getOption('set-default'); if ($default && count($theme) > 1) { $io->error($this->trans('commands.theme.install.messages.invalid-theme-default')); return; } $themes = $this->themeHandler->rebuildThemeData(); $themesAvailable = []; $themesInstalled = []; $themesUnavailable = []; foreach ($theme as $themeName) { if (isset($themes[$themeName]) && $themes[$themeName]->status == 0) { $themesAvailable[] = $themes[$themeName]->info['name']; } elseif (isset($themes[$themeName]) && $themes[$themeName]->status == 1) { $themesInstalled[] = $themes[$themeName]->info['name']; } else { $themesUnavailable[] = $themeName; } } if (count($themesAvailable) > 0) { try { if ($this->themeHandler->install($theme)) { if (count($themesAvailable) > 1) { $io->info(sprintf($this->trans('commands.theme.install.messages.themes-success'), implode(',', $themesAvailable))); } else { if ($default) { // Set the default theme. $config->set('default', $theme[0])->save(); $io->info(sprintf($this->trans('commands.theme.install.messages.theme-default-success'), $themesAvailable[0])); } else { $io->info(sprintf($this->trans('commands.theme.install.messages.theme-success'), $themesAvailable[0])); } } } } catch (UnmetDependenciesException $e) { $io->error(sprintf($this->trans('commands.theme.install.messages.success'), $theme)); drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error'); } } elseif (empty($themesAvailable) && count($themesInstalled) > 0) { if (count($themesInstalled) > 1) { $io->info(sprintf($this->trans('commands.theme.install.messages.themes-nothing'), implode(',', $themesInstalled))); } else { $io->info(sprintf($this->trans('commands.theme.install.messages.theme-nothing'), implode(',', $themesInstalled))); } } else { if (count($themesUnavailable) > 1) { $io->error(sprintf($this->trans('commands.theme.install.messages.themes-missing'), implode(',', $themesUnavailable))); } else { $io->error(sprintf($this->trans('commands.theme.install.messages.theme-missing'), implode(',', $themesUnavailable))); } } // Run cache rebuild to see changes in Web UI $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }
protected function getDirectoryData() { $systemTheme = $this->configFactory->get('system.theme'); $themeDefaultDirectory = ''; $themeAdminDirectory = ''; try { $themeDefault = $this->themeHandler->getTheme($systemTheme->get('default')); $themeDefaultDirectory = sprintf('/%s', $themeDefault->getpath()); $themeAdmin = $this->themeHandler->getTheme($systemTheme->get('admin')); $themeAdminDirectory = sprintf('/%s', $themeAdmin->getpath()); } catch (\Exception $e) { } $systemFile = $this->configFactory->get('system.file'); return ['directory' => [$this->trans('commands.site.status.messages.directory_root') => $this->appRoot, $this->trans('commands.site.status.messages.directory_temporary') => $systemFile->get('path.temporary'), $this->trans('commands.site.status.messages.directory_theme_default') => $themeDefaultDirectory, $this->trans('commands.site.status.messages.directory_theme_admin') => $themeAdminDirectory]]; }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); try { $theme = $input->getOption('theme') ? $this->validator->validateModuleName($input->getOption('theme')) : null; } catch (\Exception $error) { $io->error($error->getMessage()); return; } if (!$theme) { $validators = $this->validator; $theme = $io->ask($this->trans('commands.generate.theme.questions.theme'), '', function ($theme) use($validators) { return $validators->validateModuleName($theme); }); $input->setOption('theme', $theme); } try { $machine_name = $input->getOption('machine-name') ? $this->validator->validateModule($input->getOption('machine-name')) : null; } catch (\Exception $error) { $io->error($error->getMessage()); return; } if (!$machine_name) { $machine_name = $io->ask($this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($theme), function ($machine_name) use($validators) { return $validators->validateMachineName($machine_name); }); $input->setOption('machine-name', $machine_name); } $theme_path = $input->getOption('theme-path'); if (!$theme_path) { $drupalRoot = $this->appRoot; $theme_path = $io->ask($this->trans('commands.generate.theme.questions.theme-path'), '/themes/custom', function ($theme_path) use($drupalRoot, $machine_name) { $theme_path = ($theme_path[0] != '/' ? '/' : '') . $theme_path; $full_path = $drupalRoot . $theme_path . '/' . $machine_name; if (file_exists($full_path)) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.theme.errors.directory-exists'), $full_path)); } else { return $theme_path; } }); $input->setOption('theme-path', $theme_path); } $description = $input->getOption('description'); if (!$description) { $description = $io->ask($this->trans('commands.generate.theme.questions.description'), 'My Awesome theme'); $input->setOption('description', $description); } $package = $input->getOption('package'); if (!$package) { $package = $io->ask($this->trans('commands.generate.theme.questions.package'), 'Other'); $input->setOption('package', $package); } $core = $input->getOption('core'); if (!$core) { $core = $io->ask($this->trans('commands.generate.theme.questions.core'), '8.x'); $input->setOption('core', $core); } $base_theme = $input->getOption('base-theme'); if (!$base_theme) { $themes = $this->themeHandler->rebuildThemeData(); $themes['false'] = ''; uasort($themes, 'system_sort_modules_by_info_name'); $base_theme = $io->choiceNoList($this->trans('commands.generate.theme.options.base-theme'), array_keys($themes)); $input->setOption('base-theme', $base_theme); } $global_library = $input->getOption('global-library'); if (!$global_library) { $global_library = $io->ask($this->trans('commands.generate.theme.questions.global-library'), 'global-styling'); $input->setOption('global-library', $global_library); } // --regions option. $regions = $input->getOption('regions'); if (!$regions) { if ($io->confirm($this->trans('commands.generate.theme.questions.regions'), true)) { // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion $regions = $this->regionQuestion($io); $input->setOption('regions', $regions); } } // --breakpoints option. $breakpoints = $input->getOption('breakpoints'); if (!$breakpoints) { if ($io->confirm($this->trans('commands.generate.theme.questions.breakpoints'), true)) { // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion $breakpoints = $this->breakpointQuestion($io); $input->setOption('breakpoints', $breakpoints); } } }
/** * Tests getting the base themes for a set a defines themes. * * @param array $themes * An array of available themes, keyed by the theme name. * @param string $theme * The theme name to find all its base themes. * @param array $expected * The expected base themes. * * @dataProvider providerTestGetBaseThemes */ public function testGetBaseThemes(array $themes, $theme, array $expected) { $base_themes = $this->themeHandler->getBaseThemes($themes, $theme); $this->assertEquals($expected, $base_themes); }