Issue #3325175 by Spokje, mondrake, andypost, xjm: Deprecate calling \Drupal\menu_link_content\Form\MenuLinkContentForm::_construct() with the $language_manager argument

merge-requests/4287/head
catch 2023-06-21 15:26:13 +01:00
parent ae4b7247b8
commit d704aa3827
3 changed files with 64 additions and 19 deletions

View File

@ -3,6 +3,7 @@
namespace Drupal\menu_link_content\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
@ -19,6 +20,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class MenuLinkContentForm extends ContentEntityForm {
use DeprecatedServicePropertyTrait;
/**
* The deprecated properties and services on this class.
*/
protected array $deprecatedProperties = ['languageManager' => 'language_manager'];
/**
* The content menu link.
*
@ -28,17 +36,13 @@ class MenuLinkContentForm extends ContentEntityForm {
/**
* The parent form selector service.
*
* @var \Drupal\Core\Menu\MenuParentFormSelectorInterface
*/
protected $menuParentSelector;
protected MenuParentFormSelectorInterface $menuParentSelector;
/**
* The path validator.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
protected PathValidatorInterface $pathValidator;
/**
* Constructs a MenuLinkContentForm object.
@ -47,19 +51,23 @@ class MenuLinkContentForm extends ContentEntityForm {
* The entity repository.
* @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector
* The menu parent form selector service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* @param \Drupal\Core\Path\PathValidatorInterface|\Drupal\Core\Language\LanguageManagerInterface $path_validator
* The path validator.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\Drupal\Core\Path\PathValidatorInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* @param \Drupal\Component\Datetime\TimeInterface|\Drupal\Core\Entity\EntityTypeBundleInfoInterface $time
* The time service.
*/
public function __construct(EntityRepositoryInterface $entity_repository, MenuParentFormSelectorInterface $menu_parent_selector, LanguageManagerInterface $language_manager, PathValidatorInterface $path_validator, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
public function __construct(EntityRepositoryInterface $entity_repository, MenuParentFormSelectorInterface $menu_parent_selector, PathValidatorInterface|LanguageManagerInterface $path_validator, EntityTypeBundleInfoInterface|PathValidatorInterface $entity_type_bundle_info = NULL, TimeInterface|EntityTypeBundleInfoInterface $time = NULL) {
if ($path_validator instanceof LanguageManagerInterface) {
$path_validator = func_get_arg(3);
$entity_type_bundle_info = func_get_arg(4);
$time = func_get_arg(5);
@trigger_error('Calling ' . __CLASS__ . '::__construct() with the $language_manager argument is deprecated in drupal:10.2.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3325178', E_USER_DEPRECATED);
}
$this->menuParentSelector = $menu_parent_selector;
$this->pathValidator = $path_validator;
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
}
/**
@ -69,7 +77,6 @@ class MenuLinkContentForm extends ContentEntityForm {
return new static(
$container->get('entity.repository'),
$container->get('menu.parent_form_selector'),
$container->get('language_manager'),
$container->get('path.validator'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time')

View File

@ -0,0 +1,43 @@
<?php
namespace Drupal\Tests\menu_link_content\Kernel;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\menu_link_content\Form\MenuLinkContentForm;
/**
* Tests the deprecation notices of the menu_link_content module.
*
* @group menu_link_content
* @group legacy
*/
class MenuLinkContentDeprecationsTest extends KernelTestBase {
/**
* Tests the deprecation in the \Drupal\menu_link_content\Form\MenuLinkContentForm constructor.
*/
public function testMenuLinkContentFormConstructorDeprecation(): void {
$entity_repository = $this->prophesize(EntityRepositoryInterface::class);
$menu_parent_form_selector = $this->prophesize(MenuParentFormSelectorInterface::class);
$language_manager = $this->prophesize(LanguageManagerInterface::class);
$path_validator = $this->prophesize(PathValidatorInterface::class);
$entity_type_bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class);
$time = $this->prophesize(TimeInterface::class);
$this->expectDeprecation('Calling Drupal\menu_link_content\Form\MenuLinkContentForm::__construct() with the $language_manager argument is deprecated in drupal:10.2.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3325178');
new MenuLinkContentForm(
$entity_repository->reveal(),
$menu_parent_form_selector->reveal(),
$language_manager->reveal(),
$path_validator->reveal(),
$entity_type_bundle_info->reveal(),
$time->reveal()
);
}
}

View File

@ -1460,11 +1460,6 @@ parameters:
count: 1
path: modules/media_library/tests/src/FunctionalJavascript/EmbeddedFormWidgetTest.php
-
message: "#^Constructor of class Drupal\\\\menu_link_content\\\\Form\\\\MenuLinkContentForm has an unused parameter \\$language_manager\\.$#"
count: 1
path: modules/menu_link_content/src/Form/MenuLinkContentForm.php
-
message: "#^Method Drupal\\\\menu_link_content\\\\Form\\\\MenuLinkContentForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
count: 1