Replace AccountProxyInterface with interface implemented by User class

Created on 24 January 2024, 10 months ago
Updated 23 February 2024, 9 months ago

Currently it's not possible to use \Drupal::service('agreement.handler'), if you want to do anything for a user that is not the current user.

F.e. I need to write an agreement automatically for a new created user, created by a custom module at cron run, therfore there is no current user available and it's not possible to create an AccountProxyInterface by code.

✨ Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany slowflyer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @slowflyer
  • First commit to issue fork.
  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

    This is a good idea. Thank you.

    I think rather than using UserInterface, we can use AccountInterface, which the User entity also implements via UserInterface.

  • Status changed to RTBC 10 months ago
  • πŸ‡©πŸ‡ͺGermany slowflyer

    RTBC +1

  • Status changed to Needs work 10 months ago
  • πŸ‡©πŸ‡ͺGermany slowflyer

    Deprecated function: str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\agreement\AgreementHandler->getAgreementByUserAndPath() (Zeile 154 in /mnt/web/mafo/html/modules/contrib/agreement/src/AgreementHandler.php)

    Error occurs if:
    $public_file_path = $this->settings->get('file_public_path')

    $public_file_path is null. Seems php8.2 does not like it.

    public function getAgreementByUserAndPath(AccountInterface $account, $path) {
        $agreement_types = $this->entityTypeManager->getStorage('agreement')->loadMultiple();
    
        $default_exceptions = [
          '/user/password',
          '/user/register',
          '/user/reset/*',
          '/user/login',
          '/user/logout',
          '/admin/config/people/agreement',
          '/admin/config/people/agreement/*',
          '/admin/config/people/agreement/manage/*',
        ];
    
        if ($public_file_path = $this->settings->get('file_public_path')) {
          $public_file_path = str_starts_with($public_file_path, '/')
            ? $public_file_path . '/*'
            : '/' . $public_file_path . '/*';
          // Adds the public file path to the default exceptions.
          $default_exceptions[] = $public_file_path;
        }
    ...
    

    would fix it.

  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

    Okay, made a couple of fixes, and I think this is ready again. Thank you for the review.

  • Status changed to RTBC 10 months ago
  • πŸ‡©πŸ‡ͺGermany slowflyer

    RTBC +1

  • Pipeline finished with Skipped
    10 months ago
    #91453
  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

    Merged. Thank you again for your review and opening up the issue.

    I'll make a new alpha release shortly to help in your implementation.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024