Problem/Motivation
tca_entity_access() fires for every entity load but does not check that \Drupal::request()->query->get('tca') returns a token.
As a result, it fires return \Drupal::service('tca.tca_access_check')->access($entity, substr($user_token, 0, 255), $account);
Which throws:
Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/docroot/modules/contrib/tca/tca.module on line 88
Steps to reproduce
Enable the module. Reload the page.
Proposed resolution
Fix the call.
Remaining tasks
Make this a proper patch / MR:
/**
* Implements hook_entity_access().
*/
function tca_entity_access(EntityInterface $entity, $operation, AccountInterface $account): AccessResult|bool {
$neutral = AccessResult::neutral()
->addCacheableDependency($entity)
->addCacheContexts(['url.path']);
if ($operation !== 'view') {
return $neutral;
}
$user_token = \Drupal::request()->query->get('tca');
if (empty($user_token)) {
return $neutral;
}
return \Drupal::service('tca.tca_access_check')->access($entity, substr($user_token, 0, 255), $account);
}
Issue fork tca-3613926
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:
- 3613926-warnings-thrown-for
changes, plain diff MR !14
Comments
Comment #3
agentrickardComment #4
silke commentedCan confirm that this problem exists. agentrickard's patch removes the substr() warnings - thank you!
Comment #6
lobodakyrylo commentedThanks for reporting this and providing the merge request.
I updated the implementation to use InputBag::getString(). This avoids passing null to substr() while preserving the existing access-check behavior when the token is missing.
Committed and pushed.