/** * @param $output OutputInterface * @param $table TableHelper * @param $config_name String */ private function getRestByID($output, $table, $resource_id) { // Get the list of enabled and disabled resources. $config = $this->getRestDrupalConfig(); $resourcePluginManager = $this->getPluginManagerRest(); $plugin = $resourcePluginManager->getInstance(array('id' => $resource_id)); if (empty($plugin)) { $output->writeln('[+] <error>' . sprintf($this->trans('commands.rest.debug.messages.not-found'), $resource_id) . '</error>'); return false; } $resource = $plugin->getPluginDefinition(); $configuration = array(); $configuration[$this->trans('commands.rest.debug.messages.id')] = $resource['id']; $configuration[$this->trans('commands.rest.debug.messages.label')] = (string) $resource['label']; $configuration[$this->trans('commands.rest.debug.messages.canonical_url')] = $resource['uri_paths']['canonical']; $configuration[$this->trans('commands.rest.debug.messages.status')] = isset($config[$resource['id']]) ? $this->trans('commands.rest.debug.messages.enabled') : $this->trans('commands.rest.debug.messages.disabled'); $configuration[$this->trans('commands.rest.debug.messages.provider')] = $resource['provider']; $configurationEncoded = Yaml::encode($configuration); $output->writeln($configurationEncoded); $table->render($output); $table->setHeaders([$this->trans('commands.rest.debug.messages.rest-state'), $this->trans('commands.rest.debug.messages.supported-formats'), $this->trans('commands.rest.debug.messages.supported_auth')]); foreach ($config[$resource['id']] as $method => $settings) { $table->addRow([$method, implode(', ', $settings['supported_formats']), implode(', ', $settings['supported_auth'])]); } $table->render($output); }
/** * {@inheritdoc} */ public function findAll() { $all = array(); $files = $this->findFiles(); $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->fileCacheKeySuffix); // Try to load from the file cache first. foreach ($file_cache->getMultiple(array_keys($files)) as $file => $data) { $all[$files[$file]][$this->getIdentifier($file, $data)] = $data; unset($files[$file]); } // If there are files left that were not returned from the cache, load and // parse them now. This list was flipped above and is keyed by filename. if ($files) { foreach ($files as $file => $provider) { // If a file is empty or its contents are commented out, return an empty // array instead of NULL for type consistency. try { $data = Yaml::decode(file_get_contents($file)) ?: []; } catch (InvalidDataTypeException $e) { throw new DiscoveryException("The {$file} contains invalid YAML", 0, $e); } $data[static::FILE_KEY] = $file; $all[$provider][$this->getIdentifier($file, $data)] = $data; $file_cache->set($file, $data); } } return $all; }
/** * Merges an info file into a package's info file. * * @param string $package_info * The Yaml encoded package info. * @param string $info_file_uri * The info file's URI. */ protected function mergeInfoFile($package_info, $info_file_uri) { $package_info = Yaml::decode($package_info); $existing_info = \Drupal::service('info_parser')->parse($info_file_uri); // Ensure the entire 'features' data is replaced by new data. unset($existing_info['features']); return Yaml::encode($this->featuresManager->arrayMergeUnique($existing_info, $package_info)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $messageHelper = $this->getHelperSet()->get('message'); $directory = $input->getArgument('directory'); if (!$directory) { $config = $this->getConfigFactory()->get('system.file'); $directory = $config->get('path.temporary') ?: file_directory_temp(); $directory .= '/' . CONFIG_STAGING_DIRECTORY; } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $config_export_file = $directory . '/config.tar.gz'; file_unmanaged_delete($config_export_file); try { $archiver = new ArchiveTar($config_export_file, 'gz'); $this->configManager = $this->getConfigManager(); // Get raw configuration data without overrides. foreach ($this->configManager->getConfigFactory()->listAll() as $name) { $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); } $this->targetStorage = $this->getConfigStorage(); // Get all override data from the remaining collections. foreach ($this->targetStorage->getAllCollectionNames() as $collection) { $collection_storage = $this->targetStorage->createCollection($collection); foreach ($collection_storage->listAll() as $name) { $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name))); } } } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } $messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file)); }
/** * @param $output OutputInterface * @param $table TableHelper * @param $resource_id String */ private function geViewByID($output, $table, $view_id) { $entity_manager = $this->getEntityManager(); $view = $entity_manager->getStorage('view')->load($view_id); if (empty($view)) { $output->writeln('[+] <error>' . sprintf($this->trans('commands.views.debug.messages.not-found'), $view_id) . '</error>'); return false; } $configuration = array(); $configuration[$this->trans('commands.views.debug.messages.view-id')] = $view->get('id'); $configuration[$this->trans('commands.views.debug.messages.view-name')] = (string) $view->get('label'); $configuration[$this->trans('commands.views.debug.messages.tag')] = $view->get('tag'); $configuration[$this->trans('commands.views.debug.messages.status')] = $view->status() ? $this->trans('commands.common.status.enabled') : $this->trans('commands.common.status.disabled'); $configuration[$this->trans('commands.views.debug.messages.description')] = $view->get('description'); $configurationEncoded = Yaml::encode($configuration); $output->writeln($configurationEncoded); $table->render($output); $table->setHeaders([$this->trans('commands.views.debug.messages.display-id'), $this->trans('commands.views.debug.messages.display-name'), $this->trans('commands.views.debug.messages.display-description'), $this->trans('commands.views.debug.messages.display-paths')]); $displays = $this->getDisplaysList($view); $paths = $this->getDisplayPaths($view); $output->writeln('<info>' . sprintf($this->trans('commands.views.debug.messages.display-list'), $view_id) . '</info>'); foreach ($displays as $display_id => $display) { $table->addRow([$display_id, $display['name'], $display['description'], $this->getDisplayPaths($view, $display_id)]); } $table->render($output); }
/** * Tests export of configuration. */ function testExport() { // Verify the export page with export submit button is available. $this->drupalGet('admin/config/development/configuration/full/export'); $this->assertFieldById('edit-submit', t('Export')); // Submit the export form and verify response. $this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export')); $this->assertResponse(200, 'User can access the download callback.'); // Get the archived binary file provided to user for download. $archive_data = $this->drupalGetContent(); // Temporarily save the archive file. $uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz'); // Extract the archive and verify it's not empty. $file_path = file_directory_temp() . '/' . file_uri_target($uri); $archiver = new Tar($file_path); $archive_contents = $archiver->listContents(); $this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.'); // Prepare the list of config files from active storage, see // \Drupal\config\Controller\ConfigController::downloadExport(). $storage_active = $this->container->get('config.storage'); $config_files = array(); foreach ($storage_active->listAll() as $config_name) { $config_files[] = $config_name . '.yml'; } // Assert that the downloaded archive file contents are the same as the test // site active store. $this->assertIdentical($archive_contents, $config_files); // Ensure the test configuration override is in effect but was not exported. $this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo'); $archiver->extract(file_directory_temp(), array('system.maintenance.yml')); $file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml'); $exported = Yaml::decode($file_contents); $this->assertNotIdentical($exported['message'], 'Foo'); }
/** * Merges an info file into a package's info file. * * @param string $package_info * The Yaml encoded package info. * @param string $info_file_uri * The info file's URI. */ protected function mergeInfoFile($package_info, $info_file_uri) { $package_info = Yaml::decode($package_info); /** @var \Drupal\Core\Extension\InfoParserInterface $existing_info */ $existing_info = \Drupal::service('info_parser')->parse($info_file_uri); return Yaml::encode($this->featuresManager->mergeInfoArray($existing_info, $package_info)); }
/** * {@inheritdoc} */ public function findAll() { $all = array(); foreach ($this->findFiles() as $provider => $file) { $all[$provider] = Yaml::decode(file_get_contents($file)); } return $all; }
/** * {@inheritdoc} */ protected static function getSerializer() { // Allow settings.php to override the YAML serializer. if (!isset(static::$serializer) && ($class = Settings::get('yaml_parser_class'))) { static::$serializer = $class; } return parent::getSerializer(); }
public function execute() { $file = $this->getUnaliasedPath($this->configuration['in']); $data = file_exists($file) ? YAML::decode(file_get_contents($file)) : []; $keys = explode('/', $this->configuration['key']); NestedArray::setValue($data, $keys, $this->configuration['value']); file_put_contents($file, YAML::encode($data)); }
protected function setUp() { $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Override standard', 'hidden' => TRUE); // File API functions are not available yet. $path = $this->siteDirectory . '/profiles/standard'; mkdir($path, 0777, TRUE); file_put_contents("{$path}/standard.info.yml", Yaml::encode($this->info)); parent::setUp(); }
/** * {@inheritdoc} */ protected function setUp() { $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Distribution profile', 'distribution' => array('name' => 'My Distribution', 'langcode' => $this->langcode, 'install' => array('theme' => 'bartik'))); // File API functions are not available yet. $path = $this->siteDirectory . '/profiles/mydistro'; mkdir($path, 0777, TRUE); file_put_contents("{$path}/mydistro.info.yml", Yaml::encode($this->info)); parent::setUp(); }
/** * @param $config_name String * * @return array */ protected function getYamlConfig($config_name) { $configStorage = $this->getConfigStorage(); if ($configStorage->exists($config_name)) { $configuration = $configStorage->read($config_name); $configurationEncoded = Yaml::encode($configuration); } return $configurationEncoded; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $sweets_list = drupal_get_path('module', 'breakfast') . '/sweets.yml'; $sweets = Yaml::decode(file_get_contents($sweets_list)); foreach ($sweets as $key => $sweet) { $this->derivatives[$key] = $base_plugin_definition; $this->derivatives[$key] += array('label' => $sweet['label'], 'image' => $sweet['image'], 'ingredients' => $sweet['ingredients']); } return $this->derivatives; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $config_text = $form_state->getValue('config') ?: 'attributes:'; try { $form_state->set('config', Yaml::decode($config_text)); } catch (InvalidDataTypeException $e) { $form_state->setErrorByName('config', $e->getMessage()); } parent::validateForm($form, $form_state); }
/** * Tests that serialization of server entities doesn't lead to data loss. */ public function testServerSerialization() { // As our test server, just use the one from the DB Defaults module. $path = __DIR__ . '/../../../search_api_db/search_api_db_defaults/config/optional/search_api.server.default_server.yml'; $values = Yaml::decode(file_get_contents($path)); $server = new Server($values, 'search_api_server'); $serialized = unserialize(serialize($server)); $this->assertNotEmpty($serialized); $this->assertEquals($server, $serialized); }
protected static function yamlDecode($file, $aliases = []) { $code = "alias:\n"; $aliases['path'] = dirname($file); $yaml = new Dumper(); $yaml->setIndentation(2); foreach ($aliases as $key => $value) { $code .= ' - &' . $key . "\n" . $yaml->dump($value, PHP_INT_MAX, 4, TRUE, FALSE) . "\n"; } return Yaml::decode($code . file_get_contents($file)); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('jquery_ui_filter.settings'); $data = $form_state->getValue('jquery_ui_filter'); foreach (jQueryUiFilter::$widgets as $name => $widget) { $data[$name]['options'] = (Yaml::decode($data[$name]['options']) ?: []) + $widget['options']; } $config->setData($data); $config->save(); parent::submitForm($form, $form_state); }
/** * Tests that serialization of index entities doesn't lead to data loss. */ public function testIndexSerialization() { // As our test index, just use the one from the DB Defaults module. $path = __DIR__ . '/../../../search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml'; $index_values = Yaml::decode(file_get_contents($path)); $index = new Index($index_values, 'search_api_index'); /** @var \Drupal\search_api\IndexInterface $serialized */ $serialized = unserialize(serialize($index)); $this->assertNotEmpty($serialized); $this->assertEquals($index, $serialized); }
protected function addRouteAttributes($attr, $attributes = null) { foreach ($attr as $key => $value) { if (is_array($value)) { $attributes[] = [' ' . $key, str_replace('- ', '', Yaml::encode($value))]; } else { $attributes[] = [' ' . $key, $value]; } } return $attributes; }
/** * @param $output OutputInterface * @param $table TableHelper * @param $config_name String */ private function getConfigurationByName($output, $table, $config_name) { $configStorage = $this->getConfigStorage(); if ($configStorage->exists($config_name)) { $table->setHeaders([$config_name]); $configuration = $configStorage->read($config_name); $configurationEncoded = Yaml::encode($configuration); $table->addRow([$configurationEncoded]); } $table->render($output); }
/** * {@inheritdoc} */ public function convert(TargetInterface $target) { parent::convert($target); if ($this->defaults && $this->schema) { $group = $target->id() . '.settings'; $this->write($target, InstallStorage::CONFIG_INSTALL_DIRECTORY . '/' . $group . '.yml', Yaml::encode($this->defaults)); $this->defaults = []; $schema = [$group => ['type' => 'mapping', 'label' => (string) $this->t('Settings'), 'mapping' => $this->schema]]; $this->write($target, InstallStorage::CONFIG_SCHEMA_DIRECTORY . '/' . $target->id() . '.schema.yml', Yaml::encode($schema)); $this->schema = []; } }
/** * @param $output OutputInterface * @param $table TableHelper * @param $config_name String */ private function getTestByID($output, $table, $test_id) { $testing_groups = $this->getTestDiscovery()->getTestClasses(null); foreach ($testing_groups as $testing_group => $tests) { foreach ($tests as $key => $test) { break; } } $configurationEncoded = Yaml::encode($test); $table->addRow([$configurationEncoded]); $table->render($output); }
/** * @param $group String */ private function getBreakpointByName($group) { $breakpointsManager = $this->getDrupalService('breakpoint.manager'); $typeExtension = implode(',', array_values($breakpointsManager->getGroupProviders($group))); if ($typeExtension == 'theme') { $projectPath = drupal_get_path('theme', $group); } if ($typeExtension == 'module') { $projectPath = drupal_get_path('module', $group); } return Yaml::decode(file_get_contents($projectPath . '/' . $group . '.breakpoints.yml')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $key = $input->getArgument('key'); if ($key) { $state = $this->getState(); $io->writeln(sprintf('<info>%s:</info>', $key)); $io->writeln(Yaml::encode($state->get($key))); return; } $this->showAllStateKeys($io); }
/** * @param $io DrupalStyle * @param $config_name String */ private function getConfigurationByName(DrupalStyle $io, $config_name) { if ($this->configStorage->exists($config_name)) { $tableHeader = [$config_name]; $configuration = $this->configStorage->read($config_name); $configurationEncoded = Yaml::encode($configuration); $tableRows = []; $tableRows[] = [$configurationEncoded]; $io->table($tableHeader, $tableRows, 'compact'); } else { $io->error(sprintf($this->trans('commands.config.debug.errors.not-exists'), $config_name)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $settingKeys = array_keys($this->settings->getAll()); $io->newLine(); $io->info($this->trans('commands.config.settings.debug.messages.current')); $io->newLine(); foreach ($settingKeys as $settingKey) { $io->comment($settingKey, false); $io->simple(Yaml::encode($this->settings->get($settingKey))); } $io->newLine(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $key = $input->getArgument('key'); if ($key) { $io->info($key); $io->writeln(Yaml::encode($this->state->get($key))); return 0; } $tableHeader = [$this->trans('commands.state.debug.messages.key')]; $keyStoreStates = array_keys($this->keyValue->get('state')->getAll()); $io->table($tableHeader, $keyStoreStates); return 0; }
/** * Test ConfigDevelAutoExportSubscriber::writeBackConfig(). */ public function testWriteBackConfig() { $config_data = array('id' => $this->randomMachineName(), 'langcode' => 'en', 'uuid' => '836769f4-6791-402d-9046-cc06e20be87f'); $config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('getName')->will($this->returnValue($this->randomMachineName())); $config->expects($this->any())->method('get')->will($this->returnValue($config_data)); $file_names = array(vfsStream::url('public://' . $this->randomMachineName() . '.yml'), vfsStream::url('public://' . $this->randomMachineName() . '.yml')); $configDevelSubscriber = new ConfigDevelAutoExportSubscriber($this->configFactory, $this->configManager); $configDevelSubscriber->writeBackConfig($config, $file_names); $data = $config_data; unset($data['uuid']); foreach ($file_names as $file_name) { $this->assertEquals($data, Yaml::decode(file_get_contents($file_name))); } }
/** * @param $io * @param $eventId * @return bool */ private function getEventDetails(DrupalStyle $io, $eventId) { $connection = $this->getDrupalService('database'); $dateFormatter = $this->getDrupalService('date.formatter'); $userStorage = $this->getDrupalService('entity_type.manager')->getStorage('user'); $severity = RfcLogLevel::getLevels(); $dblog = $connection->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(':id' => $eventId))->fetchObject(); if (!$dblog) { $io->error(sprintf($this->trans('commands.database.log.debug.messages.not-found'), $eventId)); return false; } $user = $userStorage->load($dblog->uid); $configuration = [$this->trans('commands.database.log.debug.messages.event-id') => $eventId, $this->trans('commands.database.log.debug.messages.type') => $dblog->type, $this->trans('commands.database.log.debug.messages.date') => $dateFormatter->format($dblog->timestamp, 'short'), $this->trans('commands.database.log.debug.messages.user') => $user->getUsername() . ' (' . $user->id() . ')', $this->trans('commands.database.log.debug.messages.severity') => (string) $severity[$dblog->severity], $this->trans('commands.database.log.debug.messages.message') => Html::decodeEntities(strip_tags($this->formatMessage($dblog)))]; $io->writeln(Yaml::encode($configuration)); return true; }