You are here

public function WebformHelpManager::buildLibraries in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformHelpManager.php \Drupal\webform\WebformHelpManager::buildLibraries()

Build the libraries section.

Parameters

bool $docs: Set to TRUE to build exportable HTML documentation.

Return value

array An render array containing the libraries section.

Overrides WebformHelpManagerInterface::buildLibraries

File

src/WebformHelpManager.php, line 577

Class

WebformHelpManager
Webform help manager.

Namespace

Drupal\webform

Code

public function buildLibraries($docs = FALSE) {
  $info = $this
    ->getHelp('config_libraries_help');
  $build = [
    'content' => [
      'description' => [
        '#markup' => $info['content'],
        '#suffix' => '<p><hr /></p>',
      ],
      'libraries' => [
        '#prefix' => '<dl>',
        '#suffix' => '</dl>',
      ],
    ],
  ];
  $libraries = $this->librariesManager
    ->getLibraries();
  foreach ($libraries as $library_name => $library) {
    if ($docs && !empty($library['deprecated'])) {
      continue;
    }

    // Get required elements.
    $elements = [];
    if (!empty($library['elements'])) {
      foreach ($library['elements'] as $element_name) {
        $element = $this->elementManager
          ->getDefinition($element_name);
        $elements[] = $element['label'];
      }
    }
    $build['content']['libraries'][$library_name] = [
      'title' => [
        '#type' => 'link',
        '#title' => $library['title'],
        '#url' => $library['homepage_url'],
        '#prefix' => '<dt>',
        '#suffix' => ' (' . $library['version'] . ')</dt>',
      ],
      'description' => [
        'content' => [
          '#markup' => $library['description'],
          '#suffix' => '<br />',
        ],
        'notes' => [
          '#markup' => $library['notes'] . ($elements ? ' <strong>' . $this
            ->formatPlural(count($elements), 'Required by @type element.', 'Required by @type elements.', [
            '@type' => WebformArrayHelper::toString($elements),
          ]) . '</strong>' : ''),
          '#prefix' => '<em>(',
          '#suffix' => ')</em><br />',
        ],
        'download' => [
          '#type' => 'link',
          '#title' => $library['download_url']
            ->toString(),
          '#url' => $library['download_url'],
        ],
        '#prefix' => '<dd>',
        '#suffix' => '</dd>',
      ],
    ];
    if ($docs) {
      $build['content']['libraries'][$library_name]['title']['#suffix'] = '</dt>';
      unset($build['content']['libraries'][$library_name]['description']['download']);
      if (isset($library['issues_url'])) {
        $issues_url = $library['issues_url'];
      }
      elseif (preg_match('#https://github.com/[^/]+/[^/]+#', $library['download_url']
        ->toString(), $match)) {
        $issues_url = Url::fromUri($match[0] . '/issues');
      }
      else {
        $issues_url = NULL;
      }
      if ($issues_url) {
        $build['content']['libraries'][$library_name]['description']['accessibility'] = [
          '#type' => 'link',
          '#title' => $this
            ->t('known accessibility issues'),
          '#url' => $issues_url
            ->setOption('query', [
            'q' => 'is:issue is:open accessibility ',
          ]),
          '#prefix' => '<em>@see ',
          '#suffix' => '</em>',
        ];
      }
    }
  }
  return $build;
}