/** * Overrides Mollom::__construct(). * * This class accounts for multiple scenarios: * - Straight low-level requests against the testing API from a custom script, * caring for API keys on its own. * - Whenever the testing mode is enabled (either through the module's * settings page or by changing the testing_mode system variable), * the client requires valid testing API keys to perform any calls. Testing * API keys are different to production API keys, need to be created first, * and may vanish at any time (whenever the testing API server is * redeployed). Since they are different, the class stores them in different * system variables. Since they can vanish at any time, the class verifies * the keys upon every instantiation, and automatically creates new testing * API keys if necessary. * - Some automated unit tests attempt to verify that authentication errors * are handled correctly by the class' error handling. The automatic * creation and recovery of testing API keys would break those assertions, * so said tests can disable the behavior by preemptively setting * $createKeys or the 'mollom.testing_create_keys' state variable to FALSE, * and manually create testing API keys (once). * * Constructor. * @param ConfigFactory $config_factory * @param ClientInterface $http_client * * @see Mollom::__construct(). */ public function __construct(ConfigFactory $config_factory, ClientInterface $http_client) { $this->config = $config_factory->get('mollom.settings'); // Some tests are verifying the production behavior of e.g. setting up API // keys, in which testing mode is NOT enabled and the test creates fake // "production" API keys on the local fake server on its own. This special // override must only be possible when executing tests. // @todo Add global test_info as condition? $testing_mode = $this->config->get('test_mode.enabled'); $module_exists = \Drupal::moduleHandler()->moduleExists('mollom_test_server'); if ($module_exists && !$testing_mode) { // Disable authentication error auto-recovery. $this->createKeys = FALSE; } else { // Do not destroy production variables when testing mode is enabled. $this->configuration_map['publicKey'] = 'test_mode.keys.public'; $this->configuration_map['privateKey'] = 'test_mode.keys.private'; $this->configuration_map['server'] = 'test_mode.api_endpoint'; } // Load and set publicKey and privateKey configuration values. parent::__construct($config_factory, $http_client); // Unless pre-set, determine whether API keys should be auto-created. if (!isset($this->createKeys)) { $this->createKeys = \Drupal::state()->get('mollom.testing_create_keys') ?: TRUE; } // Testing can require additional time. $this->requestTimeout = $this->config->get('connection_timeout_seconds', 3) + 10; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled'])); if (!$resource_id) { $resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator()); $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); $states = $plugin->availableMethods(); $state = $io->choice($this->trans('commands.rest.enable.arguments.states'), $states); $io->writeln($this->trans('commands.rest.enable.messages.selected-state') . ' ' . $state); // Get Authentication Provider and generate the question $authenticationProviders = $this->authenticationCollector->getSortedProviders(); $authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true); $io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected)); $rest_settings = $this->getRestDrupalConfig(); $rest_settings[$resource_id][$state]['supported_formats'] = $formats; $rest_settings[$resource_id][$state]['supported_auth'] = $authenticationProvidersSelected; $config = $this->configFactory->getEditable('rest.settings'); $config->set('resources', $rest_settings); $config->save(); return 0; }
/** * @covers ::rename */ public function testRename() { $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); $this->storage->expects($this->exactly(2))->method('readMultiple')->willReturnMap([[[$old->getName()], $old->getRawData()], [[$new->getName()], $new->getRawData()]]); $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($old->getCacheTags()); $this->storage->expects($this->once())->method('rename')->with($old->getName(), $new->getName()); $this->configFactory->rename($old->getName(), $new->getName()); }
/** * Get a array with all addthis_share values. * * Allow alter through 'addthis_configuration_share'. * * @todo Add static cache. * * @todo Make the adding of configuration dynamic. * SRP is lost here. */ public function getAddThisShareConfig() { $configuration = $this->getAddThisConfig(); if (isset($configuration['templates'])) { $addthis_share = ['templates' => $configuration['templates']]; } $addthis_share['templates']['twitter'] = $this->config_factory->get('addthis.settings')->get('third_party.addthis_twitter_template'); //drupal_alter('addthis_configuration_share', $configuration); return $addthis_share; }
/** * @param $io DrupalStyle */ private function getAllConfigurations(DrupalStyle $io) { $names = $this->configFactory->listAll(); $tableHeader = [$this->trans('commands.config.debug.arguments.name')]; $tableRows = []; foreach ($names as $name) { $tableRows[] = [$name]; } $io->table($tableHeader, $tableRows, 'compact'); }
/** * {@inheritdoc} */ public function getCssIncludePath() { if ($include_path = $this->configFactory->get('printable.settings')->get('css_include')) { if ($token = $this->extractCssIncludeToken($include_path)) { list(, $theme) = explode(':', trim($token, '[]')); $include_path = str_replace($token, $this->getThemePath($theme), $include_path); } return $include_path; } }
/** * {@inheritdoc} */ public function getPrintableEntities() { $compatible_entities = $this->getCompatibleEntities(); $entities = array(); foreach ($this->configFactory->get('printable.settings')->get('printable_entities') as $entity_type) { if (isset($compatible_entities[$entity_type])) { $entities[$entity_type] = $compatible_entities[$entity_type]; } } return $entities; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $composer = $input->getOption('composer'); $module = $input->getArgument('module'); $this->site->loadLegacyFile('/core/modules/system/system.module'); $coreExtension = $this->configFactory->getEditable('core.extension'); // Get info about modules available $moduleData = system_rebuild_module_data(); $moduleList = array_combine($module, $module); if ($composer) { //@TODO: check with Composer if the module is previously required in composer.json! foreach ($module as $moduleItem) { $command = sprintf('composer remove drupal/%s ', $moduleItem); $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), $moduleItem)); } } } if ($missingModules = array_diff_key($moduleList, $moduleData)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.missing'), implode(', ', $module), implode(', ', $missingModules))); return 1; } $installedModules = $coreExtension->get('module') ?: array(); if (!($moduleList = array_intersect_key($moduleList, $installedModules))) { $io->info($this->trans('commands.module.uninstall.messages.nothing')); return 0; } if (!($force = $input->getOption('force'))) { $dependencies = []; while (list($module) = each($moduleList)) { foreach (array_keys($moduleData[$module]->required_by) as $dependency) { if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && $dependency != $profile) { $dependencies[] = $dependency; } } } if (!empty($dependencies)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.dependents'), implode('", "', $moduleList), implode(', ', $dependencies))); return 1; } } try { $this->moduleInstaller->uninstall($moduleList); $io->info(sprintf($this->trans('commands.module.uninstall.messages.success'), implode(', ', $moduleList))); $io->comment(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), implode(', ', $moduleList), false)); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * Overrides the connection timeout based on module configuration. * * Constructor. * @param ConfigFactory $config_factory * @param ClientInterface $http_client * * @see Mollom::__construct(). */ public function __construct(ConfigFactory $config_factory, ClientInterface $http_client) { $this->config = $config_factory->getEditable('mollom.settings'); $this->requestTimeout = $this->config->get('connection_timeout_seconds'); $this->client = $http_client; parent::__construct(); // Set any configured server that may be different from the default. $configured_server = $this->loadConfiguration('server'); if (!empty($configured_server)) { $this->saveConfiguration('server', $configured_server); } $this->requestTimeout = $this->config->get('connection_timeout_seconds'); }
/** * Factory method to select the correct Mollom client service. * * @param ConfigFactory $config_factory * The configuration factory in order to retrieve Mollom settings data. * @param ClientInterface $http_client * An http client * @return DrupalClientInterface */ public static function createDrupalClient(ConfigFactory $config_factory, ClientInterface $http_client) { $mollom_settings = $config_factory->get('mollom.settings'); if (\Drupal::state()->get('mollom.testing_use_local') ?: FALSE) { return new DrupalTestLocalClient($config_factory, $http_client); } else { if ($mollom_settings->get('test_mode.enabled')) { return new DrupalTestClient($config_factory, $http_client); } else { return new DrupalClient($config_factory, $http_client); } } }
/** * {@inheritdoc} */ public function buildLinks(EntityInterface $entity = NULL) { $links = array(); $printable_settings = $this->configFactory->get('printable.settings'); // Build the array of links to be added to the entity. foreach ($this->printableFormatManager->getDefinitions() as $key => $definition) { $links[$key] = array('title' => $definition['title'], 'url' => Url::fromRoute('printable.show_format.' . $entity->getEntityTypeId(), array('printable_format' => $key, 'entity' => $entity->id()))); // Add target "blank" if the configuration option is set. if ($printable_settings->get('open_target_blank') && ($key == 'print' or !$printable_settings->get('save_pdf'))) { $links[$key]['attributes']['target'] = '_blank'; } } return $links; }
/** * Adds routes to enabled REST resources. * * @param \Drupal\Core\Routing\RouteBuildEvent $event * The route building event. */ public function dynamicRoutes(RouteBuildEvent $event) { $collection = $event->getRouteCollection(); $enabled_resources = $this->config->get('rest.settings')->load()->get('resources'); // Iterate over all enabled resource plugins. foreach ($enabled_resources as $id => $enabled_methods) { $plugin = $this->manager->getInstance(array('id' => $id)); foreach ($plugin->routes() as $route) { $operation = $route->getRequirement('_operation'); if ($operation) { $collection->add("services.{$operation}", $route); } } } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configName = $input->getArgument('name'); $key = $input->getArgument('key'); $value = $input->getArgument('value'); $config = $this->configFactory->getEditable($configName); $configurationOverrideResult = $this->overrideConfiguration($config, $key, $value); $config->save(); $io->info($this->trans('commands.config.override.messages.configuration'), false); $io->comment($configName); $tableHeader = [$this->trans('commands.config.override.messages.configuration-key'), $this->trans('commands.config.override.messages.original'), $this->trans('commands.config.override.messages.updated')]; $tableRows = $configurationOverrideResult; $io->table($tableHeader, $tableRows); $config->save(); }
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']); }
/** * {@inheritdoc} */ public function loadMultiple(array $names) { $result = parent::loadMultiple($names); foreach (array_keys($result) as $name) { $this->dataCollector->addConfigName($name); } return $result; }
/** * Delete given config name. * * @param String $name Given config name. */ private function removeConfig($name) { try { $this->configFactory->getEditable($name)->delete(); } catch (\Exception $e) { throw new RuntimeException($e->getMessage()); } }
/** * Extracts the links present in HTML string. * * @param string $content * The HTML of the page to be added. * * @return string * The HTML string with presence of links dependending on configuration. */ protected function extractLinks($content) { if ($this->configFactory->get('printable.settings')->get('extract_links')) { $rendered_page = $this->linkExtractor->extract($content); } else { $rendered_page = $this->linkExtractor->removeAttribute($content, 'href'); } return $rendered_page; }
/** * @covers ::setDefaultPluginId */ public function testSetDefaultPluginId() { $plugin_id = $this->randomMachineName(); $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $config->expects($this->once())->method('set')->with('plugin_id', $plugin_id)->will($this->returnSelf()); $config->expects($this->once())->method('save'); $this->configFactory->expects($this->once())->method('get')->with('currency.amount_formatter')->willReturn($config); $this->assertSame(spl_object_hash($this->sut), spl_object_hash($this->sut->setDefaultPluginId($plugin_id))); }
protected function getThemeStatus($theme) { $defaultTheme = $this->configFactory->get('system.theme')->get('default'); $status = $theme->status ? $this->trans('commands.theme.debug.messages.installed') : $this->trans('commands.theme.debug.messages.uninstalled'); if ($defaultTheme == $theme) { $status = $this->trans('commands.theme.debug.messages.default-theme'); } return $status; }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configName = $input->getArgument('config-name'); if (!$configName) { $configNames = $this->configFactory->listAll(); $configName = $io->choice('Choose a configuration', $configNames); $input->setArgument('config-name', $configName); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled'])); if (!$resource_id) { $resource_id = $io->choice($this->trans('commands.rest.disable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator()); $input->setArgument('resource-id', $resource_id); $rest_settings = $this->getRestDrupalConfig(); unset($rest_settings[$resource_id]); $config = $this->configFactory->getEditable('rest.settings'); $config->set('resources', $rest_settings); $config->save(); $io->success(sprintf($this->trans('commands.rest.disable.messages.success'), $resource_id)); return 0; }
/** * @covers ::resolveCurrencyLocale * * @expectedException \RuntimeException */ function testResolveCurrencyLocaleMissingFallback() { $this->prepareLanguageManager(); $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('get')->with('country.default')->willReturn(NULL); $this->configFactory->expects($this->once())->method('get')->with('system.data')->willReturn($config); $this->currencyLocaleStorage->expects($this->any())->method('load')->with(LocaleResolverInterface::DEFAULT_LOCALE)->willReturn(NULL); // Test loading the fallback locale. $this->sut->resolveCurrencyLocale(); }
/** * Creates a render array for the search page. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param \Drupal\search\SearchPageInterface $entity * The search page entity. * * @return array * The search form and search results build array. */ public function view(Request $request, SearchPageInterface $entity) { $build = array(); $plugin = $entity->getPlugin(); // Build the form first, because it may redirect during the submit, // and we don't want to build the results based on last time's request. if ($request->query->has('keys')) { $keys = trim($request->get('keys')); $plugin->setSearch($keys, $request->query->all(), $request->attributes->all()); } $build['search_form'] = $this->entityFormBuilder()->getForm($entity, 'search'); // Build search results, if keywords or other search parameters are in the // GET parameters. Note that we need to try the search if 'keys' is in // there at all, vs. being empty, due to advanced search. $results = array(); if ($request->query->has('keys')) { if ($plugin->isSearchExecutable()) { // Log the search. if ($this->configFactory->get('search.settings')->get('logging')) { watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()), WATCHDOG_NOTICE); } // Collect the search results. $results = $plugin->buildResults(); } else { // The search not being executable means that no keywords or other // conditions were entered. drupal_set_message($this->t('Please enter some keywords.'), 'error'); } } if (count($results)) { $build['search_results_title'] = array('#markup' => '<h2>' . $this->t('Search results') . '</h2>'); } $no_results = t('<ul> <li>Check if your spelling is correct.</li> <li>Remove quotes around phrases to search for each word individually. <em>bike shed</em> will often show more results than <em>"bike shed"</em>.</li> <li>Consider loosening your query with <em>OR</em>. <em>bike OR shed</em> will often show more results than <em>bike shed</em>.</li> </ul>'); $build['search_results'] = array('#theme' => array('item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'), '#items' => $results, '#empty' => array('#markup' => '<h3>' . $this->t('Your search yielded no results.') . '</h3>' . $no_results), '#list_type' => 'ol', '#attributes' => array('class' => array('search-results', $plugin->getPluginId() . '-results')), '#cache' => array('tags' => $entity->getCacheTag())); $build['pager'] = array('#theme' => 'pager'); $build['#attached']['library'][] = 'search/drupal.search.results'; return $build; }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Mock the Config object, but methods will be mocked in the test class. $this->config = $this->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')->disableOriginalConstructor()->getMock(); // Mock the ConfigFactory service. $this->configFactory = $this->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')->disableOriginalConstructor()->getMock(); $this->configFactory->expects($this->any())->method('get')->with('key.default_config')->willReturn($this->config); // Mock ConfigEntityStorage object, but methods will be mocked in the test // class. $this->configStorage = $this->getMockBuilder('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock(); // Mock EntityManager service. $this->entityManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityManager')->disableOriginalConstructor()->getMock(); $this->entityManager->expects($this->any())->method('getStorage')->with('key')->willReturn($this->configStorage); // Create a dummy container. $this->container = new ContainerBuilder(); $this->container->set('entity.manager', $this->entityManager); $this->container->set('config.factory', $this->configFactory); // Each test class should call \Drupal::setContainer() in its own setUp // method so that test classes can add mocked services to the container // without affecting other test classes. }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $theme = $this->configFactory->get('system.theme')->get('default'); $themeRegions = \system_region_list($theme, REGIONS_VISIBLE); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.plugin.block.options.class'), 'DefaultBlock', function ($class) { return $this->validator->validateClassName($class); return $this->validator->validateClassName($class); }); $input->setOption('class', $class); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.block.options.label'), $this->stringConverter->camelCaseToHuman($class)); $input->setOption('label', $label); } // --plugin-id option $pluginId = $input->getOption('plugin-id'); if (!$pluginId) { $pluginId = $io->ask($this->trans('commands.generate.plugin.block.options.plugin-id'), $this->stringConverter->camelCaseToUnderscore($class)); $input->setOption('plugin-id', $pluginId); } // --theme-region option $themeRegion = $input->getOption('theme-region'); if (!$themeRegion) { $themeRegion = $io->choiceNoList($this->trans('commands.generate.plugin.block.options.theme-region'), array_values($themeRegions), null, true); $themeRegion = array_search($themeRegion, $themeRegions); $input->setOption('theme-region', $themeRegion); } // --services option // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($io); $input->setOption('services', $services); $output->writeln($this->trans('commands.generate.plugin.block.messages.inputs')); // @see Drupal\Console\Command\Shared\FormTrait::formQuestion $inputs = $this->formQuestion($io); $input->setOption('inputs', $inputs); }
/** * Stores random exchange rates in the mocked config and returns them. * * @return array * An array of the same format as the return value of * \Drupal\currency\Plugin\Currency\ExchangeRateProvider\FixedRates::loadAll(). */ protected function prepareExchangeRates() { $rates = array('EUR' => array('DEM' => '1.95583', 'NLG' => '2.20371'), 'NLG' => array('EUR' => '0.453780216')); $rates_data = array(); foreach ($rates as $currency_code_from => $currency_code_from_rates) { foreach ($currency_code_from_rates as $currency_code_to => $rate) { $rates_data[] = array('currency_code_from' => $currency_code_from, 'currency_code_to' => $currency_code_to, 'rate' => $rate); } } $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $this->config->expects($this->any())->method('get')->with('rates')->willReturn($rates_data); $this->configFactory->expects($this->any())->method('get')->with('currency.exchanger.fixed_rates')->willReturn($this->config); $this->configFactory->expects($this->any())->method('getEditable')->with('currency.exchanger.fixed_rates')->willReturn($this->config); return array($rates, $rates_data); }
protected function overrideConfigurations($configurations) { $result = []; foreach ($configurations as $configName => $options) { $config = $this->configFactory->getEditable($configName); foreach ($options as $key => $value) { $original = $config->get($key); if (is_bool($original)) { $original = $original ? 'true' : 'false'; } $updated = $value; if (is_bool($updated)) { $updated = $updated ? 'true' : 'false'; } $result[$configName][] = ['configuration' => $key, 'original' => $original, 'updated' => $updated]; $config->set($key, $value); } $config->save(); } // $this->getDrupalService('settings');die(); // // $drupal = $this->getDrupalHelper(); // $fs = $this->getApplication()->getContainerHelper()->get('filesystem'); // // $cache_render = '$settings = ["cache"]["bins"]["render"] = "cache.backend.null";'; // $cache_dynamic = '$settings =["cache"]["bins"]["dynamic_page_cache"] = "cache.backend.null";'; // // $settings_file = $fs->exists($drupal->getRoot() . '/sites/default/local.settings.php')?:$drupal->getRoot() . '/sites/default/settings.php'; // chmod($drupal->getRoot() . '/sites/default/', 0775); // chmod($settings_file, 0775); // $settings_file = $fs->dumpFile($settings_file, file_get_contents($settings_file) . $cache_render . $cache_dynamic); // chmod($drupal->getRoot() . '/sites/default/', 0644); // chmod($settings_file, 0644); // @TODO: $io->commentBlock() return $result; }
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]]; }
/** * Fetch the paths that should be used when determining when to force * anonymous users to login. * * @return * An array of paths, keyed by "include", paths that should force a * login, and "exclude", paths that should be ignored. */ public function paths() { // Initialize the paths array. $paths = ['include' => [], 'exclude' => []]; // Fetch the stored paths set in the admin settings. if ($setting = $this->config_factory->get('anonymous_login.settings')->get('paths')) { // Split by each newline. $setting = explode("\n", $setting); // Iterate each path and determine if the path should be included // or excluded. foreach ($setting as $path) { if (substr($path, 0, 1) == '~') { $paths['exclude'][] = substr($path, 1); } else { $paths['include'][] = $path; } } } return $paths; }
/** * Attach the widget js to the element. * * @todo Change the scope of the addthis.js. * See if we can get the scope of the addthis.js into the header * just below the settings so that the settings can be used in the loaded * addthis.js of our module. * * @param array $element * The element to attach the JavaScript to. */ public function attachJsToElement(&$element) { $config = $this->config_factory->get('addthis.settings'); $adv_config = $this->config_factory->get('addthis.settings.advanced'); //Generate AddThisWidgetURL $fragment = []; $pubid = $config->get('analytics.addthis_profile_id'); if (isset($pubid) && !empty($pubid) && is_string($pubid)) { $fragment[] = 'pubid=' . $pubid; } if ($adv_config->get('addthis_widget_load_async')) { $fragment[] = 'async=1'; } //Always load the script with domready flag. $fragment[] = 'domready=1'; $element['#attached']['library'][] = 'addthis/addthis.widget'; $addThisConfig = $this->getAddThisConfig(); $addThisShareConfig = $this->getAddThisShareConfig(); $options = ['fragment' => implode('&', $fragment), 'external' => TRUE]; $widget_url = $adv_config->get('addthis_widget_js_url'); $widgetURL = URL::fromUri($widget_url, $options)->toString(); $element['#attached']['drupalSettings']['addThisWidget'] = ['widgetScript' => $widgetURL, 'config' => $addThisConfig, 'share' => $addThisShareConfig]; }