Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Very simple. Cleans the element-by-element array shifting done in path_admin_overview (path.admin.inc):
if ($multilanguage) {
$header[3] = $header[2];
$header[2] = array('data' => t('Language'), 'field' => 'language');
}
...
if ($multilanguage) {
$row[4] = $row[3];
$row[3] = $row[2];
$row[2] = module_invoke('locale', 'language_name', $data->language);
}
... with the wonderful PHP function array_splice, which can insert a new element in an array using array_splice($array, $offset, 0, $new_data):
if ($multilanguage) {
array_splice($header, 2, 0, array(array('data' => t('Language'), 'field' => 'language')));
}
...
if ($multilanguage) {
array_splice($row, 2, 0, module_invoke('locale', 'language_name', $data->language));
}
Patched and ran the path tests with 100% pass (102 passes).
Comment | File | Size | Author |
---|---|---|---|
#8 | 318887-path-remove-array-splice-D7.patch | 3.52 KB | Dave Reid |
path-array-splice-D7.patch | 1.37 KB | Dave Reid | |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedSimple patch. Do you have performance results?
Comment #2
Dave ReidIf anything, this will result in a very small increase in performance since we'd be using the native PHP function for this purpose. Main purpose of this patch was to simplify the code. I'll try and do some testing today.
Comment #3
Dave ReidAlright. Finally figured out how to get ab to test the admin/build/path page and not get 403 errors. Run on 2GHz Intel P4, 2000 users, 50 nodes (couldn't get devel_generate 7.x to use batch correctly) with path aliases and translation enabled. Before patch:
After patch:
Net result, very small increase in performance, but an increase nonetheless.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #5
Dries CreditAttribution: Dries commentedThanks for the little gem, and the performance testing. I've committed it to CVS HEAD.
Unfortunately, neither the new or the old code is tested: http://acquia.com/files/test-results/modules_path_path.admin.inc.html. As such, I'm marking this 'code needs work' so we can follow-up with some tests.
Thanks Dave.
Comment #6
Dries CreditAttribution: Dries commentedComment #7
Dave ReidIdeas if this should be integrated as a new test in path.test or part of the existing path admin test?
Comment #8
Dave ReidActually here's a much better way to do this without doing any array manipulation.
Comment #9
AaronBaumanLooks like #8 has been committed, so this should go back to needs work per comment #5.
Comment #10
Dave ReidAdding tag