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.

Issue fork agreement-3416656

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

slowflyer created an issue. See original summary.

mradcliffe made their first commit to this issue’s fork.

mradcliffe’s picture

Title: Replace AccountProxyInterface with User class » Replace AccountProxyInterface with interface implemented by User class
Status: Active » Needs review

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.

slowflyer’s picture

Status: Needs review » Reviewed & tested by the community

RTBC +1

slowflyer’s picture

Status: Reviewed & tested by the community » Needs work

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.

mradcliffe’s picture

Status: Needs work » Needs review

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

slowflyer’s picture

Status: Needs review » Reviewed & tested by the community

RTBC +1

  • mradcliffe committed 76816e13 on 3.0.x
    Issue #3416656 by mradcliffe, slowflyer: Replace AccountProxyInterface...
mradcliffe’s picture

Status: Reviewed & tested by the community » Fixed

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.

Status: Fixed » Closed (fixed)

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