You are here

function _drush_bootstrap_generate_docs_settings in Express 8

Generates settings documentation.

Parameters

\Drupal\bootstrap\Theme $bootstrap: The theme instance of the Drupal Bootstrap base theme.

File

themes/contrib/bootstrap/bootstrap.drush.inc, line 54
Drupal Bootstrap Drush commands.

Code

function _drush_bootstrap_generate_docs_settings(Theme $bootstrap) {
  $output[] = '<!-- @file Overview of theme settings for Drupal Bootstrap based themes. -->';
  $output[] = '<!-- @defgroup -->';
  $output[] = '<!-- @ingroup -->';
  $output[] = '# Theme Settings';
  $output[] = '';
  $output[] = 'To override a setting, open `./config/install/THEMENAME.settings.yml` and add the following:';
  $output[] = '';
  $output[] = '```yaml';
  $output[] = '# Settings';
  $output[] = '';
  $output[] = 'settings:';
  $output[] = '  SETTING_NAME: SETTING_VALUE';
  $output[] = '```';

  // Determine the groups.
  $groups = [];
  foreach ($bootstrap
    ->getSettingPlugin() as $setting) {

    // Only get the first two groups (we don't need 3rd, or more, levels).
    $_groups = array_slice($setting
      ->getGroups(), 0, 2, FALSE);
    if (!$_groups) {
      continue;
    }
    $groups[implode(' > ', $_groups)][] = $setting
      ->getPluginDefinition();
  }

  // Generate a table of each group's settings.
  foreach ($groups as $group => $settings) {
    $output[] = '';
    $output[] = '---';
    $output[] = '';
    $output[] = "### {$group}";
    $output[] = '';
    $output[] = '<table class="table table-striped table-responsive">';
    $output[] = '  <thead><tr><th class="col-xs-3">Setting name</th><th>Description and default value</th></tr></thead>';
    $output[] = '  <tbody>';
    foreach ($settings as $definition) {
      $output[] = '  <tr>';
      $output[] = '    <td class="col-xs-3">' . $definition['id'] . '</td>';
      $output[] = '    <td>';
      $output[] = '      <div class="help-block">' . str_replace('&quote;', '"', $definition['description']) . '</div>';
      $output[] = '      <pre class=" language-yaml"><code>' . Yaml::encode([
        $definition['id'] => $definition['defaultValue'],
      ]) . '</code></pre>';
      $output[] = '    </td>';
      $output[] = '  </tr>';
    }
    $output[] = '  </tbody>';
    $output[] = '</table>';
  }

  // Ensure we have link references at the bottom.
  $output[] = '';
  $output[] = '[Drupal Bootstrap]: https://www.drupal.org/project/bootstrap';
  $output[] = '[Bootstrap Framework]: http://getbootstrap.com';

  // Save the generated output to the appropriate file.
  return file_put_contents(realpath($bootstrap
    ->getPath() . '/docs/Theme-Settings.md'), implode("\n", $output)) !== FALSE;
}