Supply default values for source_options, redirect_options, and status_code

Created on 7 October 2013, about 11 years ago
Updated 24 June 2024, 5 months ago

When attempting to build a redirect programmatically, it would be nice if default values were supplied for source_options, redirect_options, and status_code. Especially status_code, as a default value is set in the UI at /admin/config/search/redirect/settings. Creating a simple redirect using the UI I noticed that source_options and redirect_options were both set to empty arrays.

At first I figured that I had the minimum necessary options by setting

$r = new stdClass;
$r->type = 'redirect';
$r->language = 'und';
$r->source = 'redirect-test';
$r->redirect = 'node/1';

What I was most surprised at was that it was the backend database which complained about the missing values. No error was thrown by PHP via the redirect module:

WD redirect: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'source_options' doesn't have a default value: INSERT INTO {redirect} (hash, type, source, redirect, language, count, access) VALUES
(:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3,
:db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array
(
    [:db_insert_placeholder_0] => uzCyeEooUd-qzxAQ9uRd024Va5pP7vet9XzmbHoJdfY
    [:db_insert_placeholder_1] => redirect
    [:db_insert_placeholder_2] => redirect-test
    [:db_insert_placeholder_3] => node/1
    [:db_insert_placeholder_4] => en
    [:db_insert_placeholder_5] => 0
    [:db_insert_placeholder_6] => 0
)
 in drupal_write_record() (line 7311 of /data/www/wetkit/includes/common.inc).

Would it make sense to add the following to redirect_save()?

if (!isset($redirect->source_options)) {
  $redirect->source_options = array();
}
if (!isset($redirect->redirect_options)) {
  $redirect->redirect_options = array();
}
if (!isset($redirect->status_code)) {
  $redirect->status_code = 0;
}
✨ Feature request
Status

Closed: works as designed

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada nerdcore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States wylbur Minneapolis, Minnesota, USA

    Since there is a viable solution in comment #1, marking this issue as closed (works as designed).

Production build 0.71.5 2024