Set Drupal Rabbit-hole settings programmatically - drupal-9

Is it possible to update Drupal Rabbit-Hole values for a node programmatically?
function my_hook_cron() {
$some_rh_service->update_rh($my_node, 'content_not_found');
}

There maybe be a better way, but the following works:
$node->set('rh_action', 'page_not_found');
$node->set('rh_redirect_response', 301);

Related

Drupal 7 User of Two diiferent base_url?

Any solution to use two different $base_url's for drupal 7. What i need to do is when i log to my site using IP/VPN,
$base_url should be xxxx.xxxx.xxxx.xxxx and
without any vpn connections $base_url should be aaaa.aaaa.aaaa.aaa.
Any solutions? I'm Using Drupal 7.54
Without really knowing why would you need this, a possible solution could be to implement hook_boot and override $base_url to suit your needs like this:
function mymodule_boot() {
if ($condition_is_met) {
global $base_url;
$base_url = $new_base_url_value;
}
}
Your condition could be to check client IP.

How do I CC someone when an order is placed?

I am using Ubercart with Drupal.
How do I CC someone when an order is placed? I will probably have to modify the code somewhere because it should only happen under a certain theme, but I'm not sure where to even edit this.
I went to admin/store/ca and created an action. I used the products as a condition and it works.
An easy solution is to use the hook_mail_alter() in a small stub module.
This hook will let you add add to the email generated by another module.
You will need to dig into the ubercart code to find the specific $mailkey for the email you want to change.
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_mail_alter/6
function myhack_mail_alter(&$message)
{
if ($message['id'] == 'the ubercart mail key')
{
//$message['headers']['Bcc'] = 'myemail#example.com';
$message['headers']['cc'] = 'myemail#example.com';
}
}
One way to find the message key is to add the following to your function, then have the site send the email. This function will dump the keys to the dblog.
watchdog('MailKey', $message['id'], {}, WATCHDOG_INFO);

Drupal Panel Pages Pathauto

I have a Panel Page set up with the path node/%node/foo and all works fine when I visit a link such as node/6/foo. However, when I visit nodealias/foo it doesn't work at all. Is it possible to get panels to work with pathauto in this way?
I am thinking I may have to implement the hook hook_url_inbound_alter and change the url myself.
I also posted a support request in the panels module here: http://drupal.org/node/1219796
As Alexey answers panels doesn't care about aliases, it only sees node/%nid
Here's a good explanation that is valid still for D7:
http://drupal.org/node/211338
To summarize and bring it up to date for D7:
Export your variant for the panel you've created and import it into the panel that overrides the default node display in Drupal.
Add Criterias to the variant so the Panel/variant is only used for the type(s) of content you want to display with this variant.
Voila :) (read the discussion at the link, else the summary will be difficult to understand)
Hope this helps - I myself have spend some time googling and trying to understand this, and I was also confused by the fact that Views DOES care about aliases...
I fixed this using the following code, you would need to alter the pattern to match the pattern of your url aliases and alter the function name to match your module's name.
function brooklands_url_inbound_alter(&$path, $original_path, $path_language) {
$pattern = '#^works\/[A-Za-z0-9]+(-[A-Za-z0-9]+)*\/images(\/\d+)?$#';
if(preg_match($pattern, $original_path)) {
$snip = substr($original_path, 0, strrpos($original_path, '/images'));
$system_path = drupal_lookup_path('source', $snip);
if($system_path) {
$tail = substr($original_path, strrpos($original_path, '/images'));
$path = $system_path . $tail;
}
}
}
You can use this module Subpathauto
it automatically makes the alias to work with subpaths, such as: nodealias/foo
The nodealias is the full alias of your node with nid=6. The third argument (foo) is added through hook_menu() by panels module to the exact alias (node/%nid/%anythingelse) and it is NOT applied to your aliased URL, so you can not use nodealias/foo url to access your panel just because it is not 'hooked' by panels module.
Changing url manually is a good idea, I think.

Check if user agreed to terms , set cookie

I'm a Drupal nub. I would like to check on every page if user (anonymouse) agreed to somekind of terms. I suppose i should write small custom module ?
Where will this condition be written
if(!$_COOKIE('confirm')){
//jQuery show confirmation form
//Set cookie for 1hour
}
maybee in page.tpl.php ? Please, give me some tips ..
If you don't want to store the info for a long time, you should use $_SESSION variable. Then in preprocess page you could check if the user has accepted and set a variable that you can use in your page.tpl.php.
user_save() accepts an array argument which you can put custom data into. This will then be loaded with your $user object and you can use in any template file.
Check out these modules:
http://drupal.org/project/legal
http://drupal.org/project/terms_of_use
The Legal and TOS modules are good if you need a login. If working with anonymous users, however, you'll need to use the rules module with https://www.drupal.org/project/rules_session_vars.

Drupal 6 knowing it's current environment

I want to write a utility function so my Drupal project knows if it's running on the development, staging or live server.
Something like:
function mymodule_is_development() {
return (//some condition) ? TRUE : FALSE;
}
Does anyone know how to do this the Drupal way? Drupal's multisite functionality should be leveraged I think...
Take a look at Environment Indicator and how it works. You can use the settings.php to set a variable, or store one in the database with variable_set.
You can also try:
global $base_url;

Resources