devdocs-8.x-1.x-dev/devdocs_export/devdocs_export.module
devdocs_export/devdocs_export.module
<?php /** * @file * Contains devdocs.module. */ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Render\Element; use Drupal\Core\Url; use Drupal\Core\Link; /** * Implements hook_help(). */ function devdocs_export_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the devdocs module. case 'help.page.devdocs_export': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('Description') . '</p>'; return $output; default: } } /** * Implements hook_form_FORM_ID_alter(). */ function devdocs_export_form_devdocs_files_form_alter(&$form, &$form_state, $form_id) { if (isset($form['files']) && is_array($form['files'])) { foreach (Element::children($form['files']) as $key) { $element = &$form['files'][$key]; $title = $element['#title']; $uri = parse_url($element['htabs']['edit_' . $title]['uri_' . $title]['#value'], PHP_URL_HOST); $uri .= parse_url($element['htabs']['edit_' . $title]['uri_' . $title]['#value'], PHP_URL_PATH); $url = file_create_url('docs/export/pdf'); $url = Url::fromUri($url); $link_options = [ 'query' => [ 'file' => $uri, ], 'attributes' => [ 'class' => 'button', ], ]; $url->setOptions($link_options); $link = Link::fromTextAndUrl(t('PDF'), $url)->toString(); $element['htabs']['htabs_output']['export_pdf'] = [ '#markup' => $link, '#group' => 'htabs', '#weight' => '-10', ]; } } }