I get the following error on Drupal's core status page after enabling Salesforce. The status page then stops rendering at "Salesforce Provider Status" throwing this error.

(1/1) ContextErrorException
User Error: Symfony\Component\Debug\Exception\ContextErrorException thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /Users/norman/Sites/ix-eu-multisite/web/core/lib/Drupal/Component/Utility/Html.php on line 424: Warning: htmlspecialchars() expects parameter 1 to be string, object given

Looking into salesforce.install it seems that there are URL-objects passed to t(). Uncommenting them quick-fixes the issue. Trying to make them a string by appending ->toString() gives me a fatal saying that these routes don't exist. This currently happens on 8.3.4, 8.3.x-dev and 8.4.x-dev.

t('No auth providers have been created. Please <a href="@href">create an auth provider</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.add_form')])
See https://git.drupalcode.org/project/salesforce/blob/8.x-3.4/salesforce.in...

t('Salesforce authentication failed. Please <a href="@href">check your auth provider settings</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.edit_form', ['salesforce_auth' => $authMan->getConfig()])])
See https://git.drupalcode.org/project/salesforce/blob/8.x-3.4/salesforce.in...

I'd provide a patch, but I'm new to this module and don't know what exactly is supposed to be linked here.

Comments

leymannx created an issue. See original summary.

norman.lol’s picture

Issue summary: View changes
aaronbauman’s picture

Version: 8.x-3.x-dev » 8.x-4.x-dev
Status: Active » Needs review
StatusFileSize
new5.67 KB

This has broken too many times, and I'm sick of re-fixing it, so I created some tests.
Attached are failing tests for 4.x.

After fixing for 4.x, similar concept should be applied for 3.x

norman.lol’s picture

That's a good idea! Can you maybe help me Aaron to kickstart understand why these routes are reported as non-existing when I ->toString() them? Maybe I can jump in then and provide a patch as well.

aaronbauman’s picture

StatusFileSize
new5.46 KB

Fixed syntax problem in test.

The patch that addresses the tests will look like this.
Note: in the 2nd change here, i've had to add not just ->toString() but also ->id(), becaues the URL generator refuses to translate an entity into a route argument. This is likely where your change was failing.

diff --git a/salesforce.install b/salesforce.install
index 1f8ca954..738bb199 100644
--- a/salesforce.install
+++ b/salesforce.install
@@ -68,7 +68,7 @@ function salesforce_get_auth_provider_requirements() {
   $authMan = \Drupal::service('plugin.manager.salesforce.auth_providers');
   if (!$authMan->hasProviders()) {
     $requirements += [
-      'description' => t('No auth providers have been created. Please <a href="@href">create an auth provider</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.add_form')]),
+      'description' => t('No auth providers have been created. Please <a href="@href">create an auth provider</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.add_form')->toString()]),
       'severity' => REQUIREMENT_ERROR,
     ];
   }
@@ -79,7 +79,7 @@ function salesforce_get_auth_provider_requirements() {
     ];
   }
   else {
-    $failMessage = t('Salesforce authentication failed. Please <a href="@href">check your auth provider settings</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.edit_form', ['salesforce_auth' => $authMan->getConfig()])]);
+    $failMessage = t('Salesforce authentication failed. Please <a href="@href">check your auth provider settings</a> to connect to Salesforce.', ['@href' => Url::fromRoute('entity.salesforce_auth.edit_form', ['salesforce_auth' => $authMan->getConfig()->id()])->toString()]);
     try {
       if (!$authMan->getToken()) {
         $requirements += [
aaronbauman’s picture

StatusFileSize
new5.46 KB

Ok, let's try again.
Test wasn't run due to incorrect namespace.

Status: Needs review » Needs work

The last submitted patch, 6: salesforce-hook_requirements_test-3083942-6-TEST-ONLY-4.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new6.96 KB

Same tests plus fix.

  • AaronBauman committed 59c7477 on 8.x-4.x
    Issue #3083942 by AaronBauman: Passing URL objects to t-function breaks...
aaronbauman’s picture

Version: 8.x-4.x-dev » 8.x-3.x-dev
Status: Needs review » Active

Committed on 4.x
Patch does not apply cleanly on 3.x - do you want to take a crack at it?

norman.lol’s picture

Yupp, I'll try to make the patch work with 3.x-dev now.

norman.lol’s picture

Hummm, I got stuck pretty fast.

Since in 3.x there's no such route entity.salesforce_auth.add_form defined in salesforce.routing.yml. The routing pattern also seems to have changed a bit from 3.x to 4.x. Adding this route as follows, brings me back to src/Entity/SalesforceAuthConfig.php which also has no add-form defined, and the default one gives me an error of entity type does not exist.

entity.salesforce_auth.add_form:
  path: '/admin/config/salesforce/authorize/add'
  defaults:
    _entity_form: '\Drupal\salesforce\Form\AuthorizeForm'
  requirements:
    _permission: 'authorize salesforce'

Are you sure that the requirements not accidentally got mixed up from 4.x into 3.x somehow and now are breaking the 3.x logic?

aaronbauman’s picture

In 3.x, the top-level auth route is the single auth form.
It's a a single, argument-free route you can point to: salesforce.authorize

NB: The pluggable auth architecture exists in 3.x, but only for forwards-compatibility to help ease the upgrade path to 4.x.
3.x is not meant to have the same config form UI as 4.x

norman.lol’s picture

Oooookay, following your lead I diffed this now on the 3.x branch.

norman.lol’s picture

StatusFileSize
new6.92 KB

Fixed severity.

norman.lol’s picture

Status: Active » Needs review

  • AaronBauman committed 7e4b395 on 8.x-3.x authored by leymannx
    Issue #3083942 by AaronBauman, leymannx: Passing URL objects to t-...
aaronbauman’s picture

Status: Needs review » Fixed

Committed - thanks for the patch!

Status: Fixed » Closed (fixed)

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