diff -u b/redirect.module b/redirect.module --- b/redirect.module +++ b/redirect.module @@ -21,7 +21,6 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\Core\Site\Settings; -use Drupal\node\Entity\NodeType; use Drupal\redirect\Entity\Redirect; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -502,22 +501,19 @@ ]; } - $type = NodeType::load($node->getType()); $form['url_redirects']['actions'] = [ '#theme' => 'links', '#links' => [], '#attributes' => ['class' => ['action-links']], ]; $form['url_redirects']['actions']['#links']['add'] = [ - 'title' => t('Add URL redirect to this %type', ['%type' => $type->label()]), + 'title' => t('Add URL redirect'), 'url' => Url::fromRoute('redirect.add', [ - 'redirect' => "/node/$nid", + 'redirect' => $node->toUrl()->getInternalPath(), 'destination' => \Drupal::destination()->get(), ]), 'attributes' => [ 'class' => 'button', - // @todo Perhaps this could be more slick and use the off_canvas dialog? - // @see https://www.drupal.org/node/2931770 'target' => '_blank', ], ]; reverted: --- b/tests/src/Functional/RedirectNodeFormTest.php +++ /dev/null @@ -1,98 +0,0 @@ -profile != 'standard') { - $this->drupalCreateContentType([ - 'type' => 'page', - 'name' => 'Basic page', - 'display_submitted' => FALSE, - ]); - } - - $this->webUser = $this->drupalCreateUser([ - 'access content', - 'create page content', - 'edit own page content', - ]); - - $this->adminUser = $this->drupalCreateUser([ - 'access content', - 'administer redirects', - 'bypass node access', - ]); - } - - /** - * Test redirect functionality on the node edit form. - */ - public function testNodeForm() { - // Login as a regular user. - $this->drupalLogin($this->webUser); - - // Create "Basic page" content with title. - // Add the node to the frontpage so we can test if teaser links are - // clickable. - $settings = [ - 'title' => $this->randomMachineName(8), - ]; - $node = $this->drupalCreateNode($settings); - - // Load the node edit form. - $this->drupalGet('node/' . $node->id() . '/edit'); - - // Make sure the redirect add button is not visible to this regular user. - $this->assertNoRaw('Add URL redirect to this '); - - // Now edit the same node as an admin user. - $this->drupalLogin($this->adminUser); - $this->drupalGet('node/' . $node->id() . '/edit'); - - // Make sure the redirect add button is visible for the admin user, and that - // the node type is correctly rendered as a placeholder. - $this->assertRaw('Add URL redirect to this Basic page'); - - // Make sure the link works as expected. - $this->clickLink('Add URL redirect to this Basic page'); - $this->assertUrl('admin/config/search/redirect/add'); - $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-redirect-redirect-0-uri']"), '/node/' . $node->id(), 'To: field correctly pre-filled.'); - } - -}