/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $link = $form_state->getValues();
     $this->linkStorage->save($link);
     drupal_set_message(t('The custom link for %loc was saved.', array('%loc' => $link['loc'])));
     $form_state->setRedirect('xmlsitemap_custom.list');
 }
 /**
  * Test adding files as custom links.
  */
 public function testCustomFileLinks()
 {
     // Test an invalid file.
     $edit['loc'] = $this->randomMachineName();
     $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
     $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
     $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
     // Test an unaccessible file .
     $edit['loc'] = '.htaccess';
     $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
     $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
     $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
     // Test a valid file.
     $edit['loc'] = 'core/misc/drupal.js';
     $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
     $this->assertText(t('The custom link for @link was saved.', array('@link' => $edit['loc'])));
     $links = $this->linkStorage->loadMultiple(array('type' => 'custom', 'loc' => $edit['loc']));
     $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
     //Test a duplicate url.
     $edit['loc'] = 'core/misc/drupal.js';
     $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
     $this->assertText(t('There is already an existing link in the sitemap with the path @link.', array('@link' => $edit['loc'])));
     $links = $this->linkStorage->loadMultiple(array('type' => 'custom', 'loc' => $edit['loc']));
     $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
 }
 protected function addSitemapLink(array $link = array())
 {
     $last_id =& drupal_static(__FUNCTION__, 1);
     $link += array('type' => 'testing', 'id' => $last_id, 'access' => 1, 'status' => 1);
     // Make the default path easier to read than a random string.
     $link += array('loc' => $link['type'] . '-' . $link['id']);
     $last_id = max($last_id, $link['id']) + 1;
     $this->linkStorage->save($link);
     return $link;
 }