Commit 5f334b94 authored by catch's avatar catch
Browse files

Issue #2871217 by michelle, dawehner, fgm, longwave, ndobromirov,...

Issue #2871217 by michelle, dawehner, fgm, longwave, ndobromirov, wizonesolutions, sivaji_ganesh_jojodae, alexpott, anmolgoyal74, elgordogrande, kleiton_rodrigues, kuldeep_mehra27, shaktik, droath, nikhil_110, ravi.shankar, mr.baileys, dcam: Handle NULL URL options in LinkFormatter::buildUrl()

(cherry picked from commit 3b6c7bbe)
parent a89b4e66
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ protected function buildUrl(LinkItemInterface $item) {
    }

    $settings = $this->getSettings();
    $options = $item->options;
    $options = $item->options ?? [];
    $options += $url->getOptions();

    // Add optional 'rel' attribute to link options.
+17 −0
Original line number Diff line number Diff line
@@ -265,4 +265,21 @@ public function getTestCases(): \Generator {
    ];
  }

  /**
   * Tests that links with NULL options are rendered correctly.
   */
  public function testNullLinkOptions(): void {
    $entity = EntityTest::create();
    $entity->field_test->setValue([
      'uri' => 'https://www.example.com',
      'options' => NULL,
    ]);

    $render_array = $entity->field_test->view([
      ['label' => 'hidden', 'settings' => []],
    ]);
    $output = (string) \Drupal::service('renderer')->renderRoot($render_array);
    $this->assertStringContainsString('<div><a href="https://www.example.com">https://www.example.com</a></div>', $output);
  }

}