Commit a22498f0 authored by catch's avatar catch

Issue #2920571 by dev.patrick, Lendude, Xtal, chanderbhushan: Inline form...

Issue #2920571 by dev.patrick, Lendude, Xtal, chanderbhushan: Inline form errors Deprecated link function
parent 344522d5
......@@ -5,14 +5,13 @@
use Drupal\Core\Form\FormElementHelper;
use Drupal\Core\Form\FormErrorHandler as CoreFormErrorHandler;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
/**
* Produces inline form errors.
......@@ -20,7 +19,6 @@
class FormErrorHandler extends CoreFormErrorHandler {
use StringTranslationTrait;
use LinkGeneratorTrait;
/**
* The renderer service.
......@@ -41,16 +39,13 @@ class FormErrorHandler extends CoreFormErrorHandler {
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* The link generation service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(TranslationInterface $string_translation, LinkGeneratorInterface $link_generator, RendererInterface $renderer, MessengerInterface $messenger) {
public function __construct(TranslationInterface $string_translation, RendererInterface $renderer, MessengerInterface $messenger) {
$this->stringTranslation = $string_translation;
$this->linkGenerator = $link_generator;
$this->renderer = $renderer;
$this->messenger = $messenger;
}
......@@ -100,7 +95,7 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st
unset($errors[$name]);
}
elseif ($is_visible_element && $has_title && $has_id) {
$error_links[] = $this->l($title, Url::fromRoute('<none>', [], ['fragment' => $form_element['#id'], 'external' => TRUE]));
$error_links[] = Link::fromTextAndUrl($title, Url::fromRoute('<none>', [], ['fragment' => $form_element['#id'], 'external' => TRUE]))->toRenderable();
unset($errors[$name]);
}
}
......
......@@ -19,7 +19,6 @@ public function alter(ContainerBuilder $container) {
->setClass(FormErrorHandler::class)
->setArguments([
new Reference('string_translation'),
new Reference('link_generator'),
new Reference('renderer'),
new Reference('messenger'),
]);
......
......@@ -5,7 +5,6 @@
use Drupal\Core\Form\FormState;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\inline_form_errors\FormErrorHandler;
use Drupal\Tests\UnitTestCase;
......@@ -48,11 +47,10 @@ class FormErrorHandlerTest extends UnitTestCase {
*/
protected function setUp() {
parent::setUp();
$this->linkGenerator = $this->createMock(LinkGeneratorInterface::class);
$this->renderer = $this->createMock(RendererInterface::class);
$this->messenger = $this->createMock(MessengerInterface::class);
$this->formErrorHandler = new FormErrorHandler($this->getStringTranslationStub(), $this->linkGenerator, $this->renderer, $this->messenger);
$this->formErrorHandler = new FormErrorHandler($this->getStringTranslationStub(), $this->renderer, $this->messenger);
}
/**
......@@ -60,11 +58,6 @@ protected function setUp() {
* @covers ::displayErrorMessages
*/
public function testDisplayErrorMessagesInline() {
$this->linkGenerator->expects($this->any())
->method('generate')
->willReturnArgument(0);
$this->messenger->expects($this->at(0))
->method('addError')
->with('no title given');
......@@ -81,7 +74,11 @@ public function testDisplayErrorMessagesInline() {
$this->renderer->expects($this->any())
->method('renderPlain')
->will($this->returnCallback(function ($render_array) {
return $render_array[0]['#markup'] . '<ul-comma-list-mock><li-mock>' . implode(array_map('htmlspecialchars', $render_array[1]['#items']), '</li-mock><li-mock>') . '</li-mock></ul-comma-list-mock>';
$links = [];
foreach ($render_array[1]['#items'] as $item) {
$links[] = htmlspecialchars($item['#title']);
}
return $render_array[0]['#markup'] . '<ul-comma-list-mock><li-mock>' . implode($links, '</li-mock><li-mock>') . '</li-mock></ul-comma-list-mock>';
}));
$form = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment