Problem/Motivation
The class attribute of a Drupal link expects an array.
The button class added in the code below casts that attribute to a string:
$form['url_redirects']['actions']['#links']['add'] = [
'title' => t('Add URL redirect'),
'url' => Url::fromRoute('redirect.add', [
'redirect' => $node->toUrl()->getInternalPath(),
'destination' => \Drupal::destination()->get(),
]),
'attributes' => [
'class' => 'button',
'target' => '_blank',
],
];
An operations that attempt to manipulate the attributes values of links (e.g., through hook_link_alter(); see use case: #2665320: Menu links to unpublished nodes are visible to privileged users) will trigger a fatal error, "Error: [] operator not supported for strings."
Proposed resolution
diff --git a/redirect.module b/redirect.module
index 5d5bae2..182dc31 100644
--- a/redirect.module
+++ b/redirect.module
@@ -372,7 +372,7 @@ function redirect_form_node_form_alter(&$form, FormStateInterface $form_state, $
'destination' => \Drupal::destination()->get(),
]),
'attributes' => [
- 'class' => 'button',
+ 'class' => ['button'],
'target' => '_blank',
],
];
Priority
The likelihood of sites performing link alters that would include the link provided by the Redirect module seem low, but on the other hand, it will provoke a fatal error. So: low frequency, high impact.
Comments
Comment #2
mark_fullmerThe attached patch provides the "button" class as an array element, respecting the Drupal core expectation and preventing a fatal error when the link attributes array is merged by other processes.
Comment #3
dave reidI just ran into this as well, looks good.
Comment #5
dave reidCommitted #2 to 8.x-1.x. Thanks!