function redirect_404_update_8102 in Redirect 8
Add daily count field to redirect_404 table and view.
File
- modules/
redirect_404/ redirect_404.install, line 74 - Update hooks for the redirect_404 module.
Code
function redirect_404_update_8102() {
\Drupal::database()
->schema()
->addField('redirect_404', 'daily_count', [
'description' => 'The number of requests with that path and language in a day.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
]);
$view_config = \Drupal::configFactory()
->getEditable('views.view.redirect_404');
if (!$view_config
->isNew()) {
$columns_key = 'display.default.display_options.style.options.columns';
$columns = $view_config
->get($columns_key);
$columns['daily_count'] = 'daily_count';
$view_config
->set($columns_key, $columns);
$info_key = 'display.default.display_options.style.options.info';
$info = $view_config
->get($info_key);
$info['daily_count'] = [
'sortable' => TRUE,
'default_sort_order' => 'desc',
'align' => '',
'separator' => '',
'empty_column' => FALSE,
'responsive' => '',
];
$view_config
->set($info_key, $info);
$fields = $view_config
->get('display.default.display_options.fields');
$daily_count = [
'id' => 'daily_count',
'table' => 'redirect_404',
'field' => 'daily_count',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => '',
'label' => 'Daily count',
'exclude' => FALSE,
'alter' => [
'alter_text' => FALSE,
'text' => '',
'make_link' => FALSE,
'path' => '',
'absolute' => FALSE,
'external' => FALSE,
'replace_spaces' => FALSE,
'path_case' => 'none',
'trim_whitespace' => FALSE,
'alt' => '',
'rel' => '',
'link_class' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'nl2br' => FALSE,
'max_length' => 0,
'word_boundary' => TRUE,
'ellipsis' => TRUE,
'more_link' => FALSE,
'more_link_text' => '',
'more_link_path' => '',
'strip_tags' => FALSE,
'trim' => FALSE,
'preserve_tags' => '',
'html' => FALSE,
],
'element_type' => '',
'element_class' => '',
'element_label_type' => '',
'element_label_class' => '',
'element_label_colon' => TRUE,
'element_wrapper_type' => '',
'element_wrapper_class' => '',
'element_default_classes' => TRUE,
'empty' => '',
'hide_empty' => FALSE,
'empty_zero' => FALSE,
'hide_alter_empty' => TRUE,
'format' => 'unserialized',
'key' => '',
'plugin_id' => 'serialized',
];
$count_index = array_search('count', array_keys($fields));
$fields = array_slice($fields, 0, $count_index + 1) + [
'daily_count' => $daily_count,
] + array_slice($fields, $count_index);
$view_config
->set('display.default.display_options.fields', $fields)
->save();
}
}