/**
  * {@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));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $config_name = '')
 {
     $config = $this->config($config_name);
     if ($config === FALSE || $config->isNew()) {
         drupal_set_message(t('Config @name does not exist in the system.', array('@name' => $config_name)), 'error');
         return;
     }
     $data = $config->get();
     if (empty($data)) {
         drupal_set_message(t('Config @name exists but has no data.', array('@name' => $config_name)), 'warning');
         return;
     }
     try {
         $output = Yaml::encode($data);
     } catch (InvalidDataTypeException $e) {
         drupal_set_message(t('Invalid data detected for @name : %error', array('@name' => $config_name, '%error' => $e->getMessage())), 'error');
         return;
     }
     $form['current'] = array('#type' => 'details', '#title' => $this->t('Current value for %variable', array('%variable' => $config_name)), '#attributes' => array('class' => array('container-inline')));
     $form['current']['value'] = array('#type' => 'item', '#markup' => dpr($output, TRUE));
     $form['name'] = array('#type' => 'value', '#value' => $config_name);
     $form['new'] = array('#type' => 'textarea', '#title' => $this->t('New value'), '#default_value' => $output, '#rows' => 24, '#required' => TRUE);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => $this->t('Cancel'), '#url' => $this->buildCancelLinkUrl());
     return $form;
 }
 /**
  * @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);
 }
 /**
  * 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));
 }
 /**
  * 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));
 }
 /**
  * @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);
 }
 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));
 }
 /**
  * {@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;
 }
 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();
 }
 /**
  * @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);
 }
 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;
 }
 /**
  * {@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 = [];
     }
 }
 /**
  * {@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 $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);
 }
 /**
  * {@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}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $option_descriptions = ['headerTag' => $this->t("<b>headerTag</b>: Header tag for widget's element"), 'mediaType' => $this->t("<b>mediaType</b>: Media type (all, screen, or print) that widget should be render to. Setting <code>mediaType</code> to <code>screen</code> will limit the display of the widget to the browser and when the page is printed the widget will default back to simple HTML markup. Setting <code>mediaType</code> to <code>all</code> allows the widget to be printed."), 'scrollTo' => $this->t('<b>scrollTo</b>: Scrolls to bookmarked widget when a page is loaded.'), 'scrollToDuration' => $this->t('<b>scrollToDuration</b>: The speed at which the page scrolls to a bookmarked widget.'), 'scrollToOffset' => $this->t("<b>scrollToOffset</b>: The offset from the top of the page that a bookmarked widget scrolls to. Setting to <code>auto</code> will include the page's body top margin and top padding when scrolling to a bookmarked widget.")];
     $config = $this->config('jquery_ui_filter.settings');
     $form['jquery_ui_filter'] = ['#tree' => TRUE];
     foreach (jQueryUiFilter::$widgets as $name => $widget) {
         $t_args = ['@name' => $name, '@api' => $widget['api']];
         $form['jquery_ui_filter'][$name] = ['#type' => 'details', '#title' => $widget['title'], '#description' => t('Learn more about <a href="@api">jQuery UI @name options</a>.', $t_args), '#open' => TRUE];
         $options_description = ['description' => ['#markup' => $this->t('Custom options:')], 'options' => ['#theme' => 'item_list', '#items' => $option_descriptions]];
         $form['jquery_ui_filter'][$name]['options'] = ['#type' => 'textarea', '#title' => $this->t('Options (YAML)'), '#description' => \Drupal::service('renderer')->render($options_description), '#default_value' => Yaml::encode(($config->get($name . '.options') ?: []) + $widget['options']), "#rows" => 6];
     }
     return parent::buildForm($form, $form_state);
 }
Exemple #18
0
 /**
  * @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);
     $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;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $group = $input->getArgument('group');
     if (!$group) {
         $groups = $this->getAllBreakpoints();
         $tableHeader = [$this->trans('commands.breakpoints.debug.messages.name')];
         $io->table($tableHeader, $groups, 'compact');
     } else {
         $breakPointData = $this->getBreakpointByName($group);
         foreach ($breakPointData as $key => $breakPoint) {
             $io->comment($key);
             $io->writeln(Yaml::encode($breakPoint));
         }
     }
 }
 /**
  * @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;
 }
 public function test()
 {
     $permissions = ['bazify' => ['title' => 'Do snazzy bazzy things']];
     $indexer = $this->getMockBuilder('\\Drupal\\drupalmoduleupgrader\\Plugin\\DMU\\Indexer\\Functions')->disableOriginalConstructor()->getMock();
     $indexer->method('has')->with('hook_permission')->willReturn(TRUE);
     $indexer->method('hasExecutable')->with('hook_permission')->willReturn(TRUE);
     $indexer->method('execute')->with('hook_permission')->willReturn($permissions);
     $this->container->get('plugin.manager.drupalmoduleupgrader.indexer')->method('createInstance')->with('function')->willReturn($indexer);
     $config = ['hook' => 'permission', 'destination' => '~/foo.permissions.yml'];
     $plugin = new HookToYAML($config, uniqID(), []);
     $plugin->setTarget($this->target);
     $plugin->execute();
     $url = $this->dir->getChild('foo.permissions.yml')->url();
     $this->assertFileExists($url);
     $this->assertSame(YAML::encode($permissions), file_get_contents($url));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $group = $input->getArgument('group');
     if (!$group) {
         $groups = $this->getAllLibraries();
         $tableHeader = [$this->trans('commands.libraries.debug.messages.name')];
         $io->table($tableHeader, $groups, 'compact');
     } else {
         $librariesData = $this->libraryDiscovery->getLibrariesByExtension($group);
         foreach ($librariesData as $key => $libraries) {
             $io->comment($key);
             $io->writeln(Yaml::encode($libraries));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $directory = $input->getOption('directory');
     $tar = $input->getOption('tar');
     $removeUuid = $input->getOption('remove-uuid');
     if (!$directory) {
         $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     }
     if ($tar) {
         if (!is_dir($directory)) {
             mkdir($directory, 0777, true);
         }
         $dateTime = new \DateTime();
         $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s'));
         $archiveTar = new ArchiveTar($archiveFile, 'gz');
     }
     try {
         // Get raw configuration data without overrides.
         foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
             $configData = $this->configManager->getConfigFactory()->get($name)->getRawData();
             $configName = sprintf('%s.yml', $name);
             // The _core is site-specific, so don't export it.
             unset($configData['_core']);
             if ($removeUuid) {
                 unset($configData['uuid']);
             }
             $ymlData = Yaml::encode($configData);
             if ($tar) {
                 $archiveTar->addString($configName, $ymlData);
                 continue;
             }
             $configFileName = sprintf('%s/%s', $directory, $configName);
             $fileSystem = new Filesystem();
             try {
                 $fileSystem->mkdir($directory);
             } catch (IOExceptionInterface $e) {
                 $io->error(sprintf($this->trans('commands.config.export.messages.error'), $e->getPath()));
             }
             file_put_contents($configFileName, $ymlData);
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
     }
     $io->info(sprintf($this->trans('commands.config.export.messages.directory'), $directory));
 }
Exemple #25
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('menu_link_attributes.config');
    $attributes = $config->get('attributes');
    $conf = ['attributes' => $attributes];
    $config_text = Yaml::encode($conf);

    if (!\Drupal::moduleHandler()->moduleExists('yaml_editor')) {
      $message = $this->t('It is recommended to install the <a href="@yaml-editor">YAML Editor</a> module for easier editing.', [
        '@yaml-editor' => 'https://www.drupal.org/project/yaml_editor',
      ]);

      drupal_set_message($message, 'warning');
    }

    $form['config'] = array(
      '#type' => 'textarea',
      '#title' => $this->t('Configuration'),
      '#description' => $this->t('Available attributes can be defined in YAML syntax.'),
      '#default_value' => $config_text,
      '#rows' => 15,
      '#attributes' => ['data-yaml-editor' => 'true'],
    );

    // Use module's YAML config file for example structure.
    $module_path = \Drupal::moduleHandler()->getModule('menu_link_attributes')->getPath();
    $yml_text = file_get_contents($module_path . '/config/install/menu_link_attributes.config.yml');

    $form['example'] = [
      '#type' => 'details',
      '#title' => $this->t('Example structure'),
    ];

    $form['example']['description'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this->t('Each attribute has an optional label and description.'),
    ];

    $form['example']['code'] = [
      '#prefix' => '<pre>',
      '#suffix' => '</pre>',
      '#markup' => $yml_text,
    ];

    return parent::buildForm($form, $form_state);
  }
 /**
  * Test the import subscriber.
  */
 public function testSubscribers()
 {
     // Without this the config exporter breaks.
     \Drupal::service('config.installer')->installDefaultConfig('module', 'config_devel');
     $filename = vfsStream::url('public://' . static::CONFIGNAME . '.yml');
     drupal_mkdir(vfsStream::url('public://exported'));
     $exported_filename = vfsStream::url('public://exported/' . static::CONFIGNAME . '.yml');
     \Drupal::configFactory()->getEditable('config_devel.settings')->set('auto_import', array(array('filename' => $filename, 'hash' => '')))->set('auto_export', array($exported_filename))->save();
     $this->storage = \Drupal::service('config.storage');
     $this->assertFalse($this->storage->exists(static::CONFIGNAME));
     $subscriber = \Drupal::service('config_devel.auto_import_subscriber');
     for ($i = 2; $i; $i--) {
         $data['label'] = $this->randomString();
         file_put_contents($filename, Yaml::encode($data));
         // The import fires an export too.
         $subscriber->autoImportConfig();
         $this->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $key = $input->getArgument('key');
     $value = $input->getArgument('value');
     if (!$key) {
         $io->error($this->trans('commands.state.override.errors.no-key'));
     }
     if (!$value) {
         $io->error($this->trans('commands.state.override.errors.no-value'));
     }
     if ($key && $value) {
         $state = $this->getState();
         $originalValue = Yaml::encode($state->get($key));
         $overrideValue = is_array($value) ? Yaml::encode($value) : $value;
         $state->set($key, $overrideValue);
         $tableHeaders = [$this->trans('commands.state.override.messages.key'), $this->trans('commands.state.override.messages.original'), $this->trans('commands.state.override.messages.override')];
         $tableRows[] = [$key, $originalValue, $overrideValue];
         $io->table($tableHeaders, $tableRows);
     }
 }
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('linked_field.config');
    $conf = $config->get();
    $config_text = Yaml::encode($conf);

    // Each attribute needs 3 rows + "attributes:" row + 3 extra lines
    // for adding a new attribute.
    $rows = (count($config->get('attributes')) * 3) + 4;

    $form['config'] = array(
      '#type' => 'textarea',
      '#title' => $this->t('Configuration'),
      '#description' => $this->t('Available attributes can be defined in YAML syntax.'),
      '#default_value' => $config_text,
      '#rows' => $rows,
    );

    // Use module's YAML config file for example structure.
    $module_path = \Drupal::moduleHandler()->getModule('linked_field')->getPath();
    $yml_text = file_get_contents($module_path . '/config/install/linked_field.config.yml');

    $form['example'] = [
      '#type' => 'details',
      '#title' => $this->t('Example structure'),
    ];

    $form['example']['description'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this->t('Each attribute has an optional label and description.')
    ];

    $form['example']['code'] = [
      '#prefix' => '<pre>',
      '#suffix' => '</pre>',
      '#markup' => $yml_text,
    ];

    return parent::buildForm($form, $form_state);
  }
 /**
  * @param $output         OutputInterface
  * @param $table          TableHelper
  * @param $config_name    String
  */
 private function getTestByID($output, $table, $test_class)
 {
     $testing_groups = $this->getTestDiscovery()->getTestClasses(null);
     $test_details = null;
     foreach ($testing_groups as $testing_group => $tests) {
         foreach ($tests as $key => $test) {
             if ($test['name'] == $test_class) {
                 $test_details = $test;
                 break;
             }
         }
         if ($test_details !== null) {
             break;
         }
     }
     $class = null;
     if ($test_details) {
         $class = new \ReflectionClass($test['name']);
         if (is_subclass_of($test_details['name'], 'PHPUnit_Framework_TestCase')) {
             $test_details['type'] = 'phpunit';
         } else {
             $test_details = $this->getTestDiscovery()->getTestInfo($test_details['name']);
             $test_details['type'] = 'simpletest';
         }
         $configurationEncoded = Yaml::encode($test_details);
         $table->addRow([$configurationEncoded]);
         $table->render($output);
         if ($class) {
             $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
             $output->writeln('[+] <info>' . $this->trans('commands.test.debug.messages.methods') . '</info>');
             foreach ($methods as $method) {
                 if ($method->class == $test_details['name'] && strpos($method->name, 'test') === 0) {
                     $output->writeln('[-] <info>' . $method->name . '</info>');
                 }
             }
         }
     } else {
         $output->writeln('[+] <error>' . $this->trans('commands.test.debug.messages.not-found') . '</error>');
     }
 }
 /**
  * @param $output         OutputInterface
  * @param $table          TableHelper
  * @param $resource_id    String
  */
 private function getEventDetails($output, $event_id)
 {
     $connection = $this->getDatabase();
     $date_formatter = $this->getDateFormatter();
     $user_storage = $this->getEntityManager()->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' => $event_id))->fetchObject();
     if (empty($dblog)) {
         $output->writeln('[+] <error>' . sprintf($this->trans('commands.dblog.debug.messages.not-found'), $event_id) . '</error>');
         return false;
     }
     $user = $user_storage->load($dblog->uid);
     $configuration = array();
     $configuration[$this->trans('commands.dblog.debug.messages.event-id')] = $event_id;
     $configuration[$this->trans('commands.dblog.debug.messages.type')] = $dblog->type;
     $configuration[$this->trans('commands.dblog.debug.messages.date')] = $date_formatter->format($dblog->timestamp, 'short');
     $configuration[$this->trans('commands.dblog.debug.messages.user')] = $user->getUsername() . ' (' . $user->id() . ')';
     $configuration[$this->trans('commands.dblog.debug.messages.severity')] = (string) $severity[$dblog->severity];
     $configuration[$this->trans('commands.dblog.debug.messages.message')] = Html::decodeEntities(strip_tags($this->formatMessage($dblog)));
     $configurationEncoded = Yaml::encode($configuration);
     $output->writeln($configurationEncoded);
 }