Commit d2cbc192 authored by Adam Shepherd's avatar Adam Shepherd Committed by Nigel Cunningham
Browse files

Issue #3213802 by AdamPS: Allow keeping links unmodified

parent a7413483
Loading
Loading
Loading
Loading
+8 −3
Changes for src/Form/PrintableConfigurationForm.php: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -119,9 +119,14 @@ class PrintableConfigurationForm extends ConfigFormBase {

    // Provide option to turn off link extraction.
    $form['settings']['extract_links'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Extract Links'),
      '#description' => $this->t('Extract any links in the content, e.g. "Some Link (http://drupal.org)'),
      '#type' => 'radios',
      '#title' => $this->t('Link handling'),
      '#description' => $this->t('Choose what happens with to any links in the content.'),
      '#options' => [
        'extract' => 'Extract (show the URL in brackets)',
        'remove' => 'Remove (delete the "href=")',
        'none' => 'Unchanged',
      ],
      '#default_value' => $this->config('printable.settings')
        ->get('extract_links'),
    ];
+10 −7
Changes for src/Plugin/PrintableFormatBase.php: 10 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -213,16 +213,19 @@ abstract class PrintableFormatBase extends PluginBase implements PrintableFormat
   *   The HTML of the page to be added.
   *
   * @return string
   *   The HTML string with presence of links dependending on configuration.
   *   The HTML string with presence of links depending on configuration.
   */
  protected function extractLinks($content) {
    if ($this->configFactory->get('printable.settings')->get('extract_links')) {
      $rendered_page = $this->linkExtractor->extract($content);
    }
    else {
      $rendered_page = $this->linkExtractor->removeAttribute($content, 'href');
    switch($this->configFactory->get('printable.settings')->get('extract_links')) {
      case 'extract':
        return $this->linkExtractor->extract($content);

      case 'remove':
        return $this->linkExtractor->removeAttribute($content, 'href');

      default:
        return $content;
    }
    return $rendered_page;
  }

  /**