Problem/Motivation

Currently, the UserRestrictionsFormBase class implements the create() method, but that is not necessary for child classes to use AutoWireTrait.

Proposed resolution

  • Remove UserRestrictionsFormBase::create()
  • Make the $typeManager property nullable; property promotion should no longer be used
  • Add a (protected) UserRestrictionsFormBase::setTypeManager() function which initializes the new property
  • Add a (protected) UserRestrictionsFormBase::getTypeManager() function which triggers an error when $typeManager has not been set, and sets $typeManager; the trigger error needs to explain that constructors for child classes needs to call UserRestrictionsFormBase::setTypeManager()
  • Change any UserRestrictionsFormBase method that directly uses $typeManager to call UserRestrictionsFormBase::getTypeManager()
  • Change the classes that extend UserRestrictionsFormBase
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

avpaderno created an issue. See original summary.

avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

Issue summary: View changes
santanu mondal’s picture

Working On It.

santanu mondal’s picture

Status: Active » Needs review

avpaderno’s picture

Status: Needs review » Needs work
santanu mondal’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work

The errors/warnings reported by GitLab need to be fixed.

santanu mondal’s picture

Hi @avpaderno I have solve the Gitlab warning please check.

santanu mondal’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work

I will review the merge request using the plain diff.

-  public const int PATTERN_ALLOW = 1;
+  public const PATTERN_ALLOW = 1;

Since the module requires PHP 8.3, typed constants are allowed. The existing code is correct.

diff --git a/src/Form/UserRestrictionAddForm.php b/src/Form/UserRestrictionAddForm.php
new file mode 100644
index 0000000000000000000000000000000000000000..c62069d5042f1e2211970b2b624b7fb997f0e74c
--- /dev/null

The file to change is src/Form/UserRestrictionsAddForm.php, which exists, not src/Form/UserRestrictionAddForm.php.

diff --git a/src/Form/UserRestrictionFormBase.php b/src/Form/UserRestrictionFormBase.php
new file mode 100644
index 0000000000000000000000000000000000000000..9de753142f91acde5159cf85c784b1de779ef5f6
--- /dev/null
+++ b/src/Form/UserRestrictionFormBase.php

The file to change is src/Form/UserRestrictionsFormBase.php, which exists, not src/Form/UserRestrictionFormBase.php.

 class UserRestrictionsAddForm extends UserRestrictionsFormBase {
+  use AutowireTrait;

Between those lines there must be an empty line.

   /**
-   * Construct a new \Drupal\user_restrictions\Form\UserRestrictionsFormBase instance.
+   * Gets the type manager service.
    *
-   * @param \Drupal\user_restrictions\UserRestrictionTypeManagerInterface $typeManager
-   *   The user restriction type manager.
+   * @return \Drupal\user_restrictions\UserRestrictionTypeManagerInterface
+   *   The user restriction type manager service.
    */

It is the user restriction type manager. A manager is a service; there is no need to say that.

+  protected function getTypeManager(): UserRestrictionTypeManagerInterface {
+    if (!$this->typeManager) {
+      @trigger_error('UserRestrictionsFormBase::getTypeManager() called without the type manager being set is deprecated in user_restrictions:2.0.0 and will be removed in user_restrictions:3.0.0. See https://www.drupal.org/node/3555932', E_USER_DEPRECATED);
+    }

UserRestrictionsFormBase::getTypeManager() does not get any parameter; that message is supposed to say that child classes needs to call UserRestrictionsFormBase::setTypeManager() in their constructors.
It is user_restrictions:2.1.1, not user_restrictions:2.0.0.

Also, for backward-compatibility reasons, that code needs to initialize $this->typeManager, when it has not been already initialized.

I would suggest to start fresh with a new issue fork created from the 2.1.x branch. (I created 3555932-allow-child-classes-to-use-AutowireTrait for this reason. It is updated with the current changes done in the 2.1.x branch.)

avpaderno changed the visibility of the branch 3555932-remove-UserRestrictionsFormBase-create to hidden.

avpaderno’s picture

Issue tags: -Needs change record

santanu mondal’s picture

Status: Needs work » Needs review
avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Needs work

avpaderno’s picture

Version: 2.1.x-dev » 3.0.x-dev

  • avpaderno committed 9ba89063 on 2.1.x
    Revert "Issue #3555932: Remove UserRestrictionsFormBase::create() to...
avpaderno’s picture

Status: Needs work » Closed (won't fix)

I reverted the change, since it was a wrong change.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.