1

I'm using the Rules module and have a Rule created that, upon saving of new content, an email is sent out containing the node title, as well as the URL of the node. Pretty straightforward. That said, I want to replace text in the URL before the message that's sent out. I'm using str_replace() but it isn't working.

Any suggestions?

Update:

The path currently look like this: domain.com/cron.php/newsroom/press-release/[path-to-content] However, I would need to replace out the "cron.php" from the URL, as that doesn't actually exist. So the new URL should look like this: domain.com/newsroom/press-release/[path-to-content]

Here's an export of the rule. I've removed any sensitive information:

{ "rules_press_release_notification_test" : {
    "LABEL" : "Press Release Notification Test",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "php" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "press_release" : "press_release" } }
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "",
          "subject" : "[node:title]",
          "message" : "We've added a new press release to our Newsroom:\r\n\r\n[node:title]\r\n\r\n\u003C?php\r\n$releaseurl = \u0022[node:url]\u0022;\r\n$releaseurl = str_replace(\u0022newsroom\/\u0022, \u0022\u0022, $releaseurl);\r\n\r\necho $releaseurl;\r\n?\u003E\r\n\r\n[node:url]\r\n",
          "language" : [ "" ]
        }
      }
    ]
  }
}
2
  • I have updated the description accordingly. Thanks!
    – cbcorbett
    Commented May 4, 2016 at 17:13
  • Wouldn't it be better to add a rewrite rule to htaccess or nginx config?
    – mbomb007
    Commented Jun 19, 2019 at 21:17

1 Answer 1

1

I would transform your existing rule into 2 separated rules like so:

  • Create a Rules Component that only performs a Rules Action which is to send an eMail, similar to what you already have in your current Rules Action. But replace the node:title and the node:url by corresponding parameters to execute this Rules Component.
  • Replace the Rules Action of the rule you already have by the execution of your newly created Rules Component, in which you pass as parameter values:
    • the title of the node
    • the appropriate string that matches your domain.com/newsroom/press-release/[path-to-content]

With that, you don't need any PHP, so no str_replace() either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.