Commit f28cbf9a authored by tadityar's avatar tadityar Committed by tadityar
Browse files

Issue #2349107 by andythorne, stella, tadityar: Replace url() and l() calls with D8 code

parent 0c5842a3
......@@ -14,6 +14,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -108,10 +109,11 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container
),
);
foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) {
$url = Url::fromRoute('xmlsitemap.admin_settings_bundle', ['entity' => $entity_type_id, 'bundle' => $bundle], array('query' => drupal_get_destination()));
$form['settings'][$entity_type_id][$bundle]['settings'] = array(
'#type' => 'item',
'#label' => $bundle_info['label'],
'#settings_link' => l($this->t('Configure'), 'admin/config/search/xmlsitemap/settings/' . $entity_type_id . '/' . $bundle, array('query' => drupal_get_destination())),
'#settings_link' => $this->l($this->t('Configure'), $url),
'bundle' => array(
'#type' => 'checkbox',
'#default_value' => xmlsitemap_link_bundle_check_enabled($entity_type_id, $bundle)
......
......@@ -12,6 +12,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
......@@ -73,7 +74,7 @@ class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase implements Contain
// If this is a non-ajax form, redirect to the bundle administration page.
$destination = drupal_get_destination();
$request->query->remove('destination');
$url = url($admin_path, array('query' => array($destination)));
$url = Url::fromUri($admin_path, array('query' => array($destination)));
return new RedirectResponse($url);
}
else {
......
......@@ -11,6 +11,7 @@ use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -65,7 +66,7 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
}
else {
$request->query->set('destination', 'admin/config/search/xmlsitemap');
drupal_set_message(t('A rebuild is not necessary. If you are just wanting to regenerate the XML sitemap files, you can <a href="@link-cron">run cron manually</a>.', array('@link-cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))), 'warning');
drupal_set_message(t('A rebuild is not necessary. If you are just wanting to regenerate the XML sitemap files, you can <a href="@link-cron">run cron manually</a>.', array('@link-cron' => Url::fromRoute('system.run_cron', [], array('query' => drupal_get_destination())))), 'warning');
$this->setRequest($request);
}
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\xmlsitemap\Tests;
use Drupal\Core\Url;
/**
* Tests the robots.txt file existance.
*/
......@@ -46,7 +48,7 @@ class XmlSitemapRobotsTxtIntegrationTest extends XmlSitemapTestBase {
return;
}
$this->drupalGet('/robots.txt');
$this->assertRaw('Sitemap: ' . url('sitemap.xml', array('absolute' => TRUE)));
$this->assertRaw('Sitemap: ' . Url::fromRoute('xmlsitemap.sitemap_xml', [], array('absolute' => TRUE)));
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\xmlsitemap\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Url;
/**
* Helper test class with some added functions for testing.
......@@ -135,7 +136,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
* @param $context
* An optional array of the XML sitemap's context.
* @param $options
* Options to be forwarded to url(). These values will be merged with, but
* Options to be forwarded to Url::fromUri(). These values will be merged with, but
* always override $sitemap->uri['options'].
* @param $headers
* An array containing additional HTTP request headers, each formatted as
......@@ -237,7 +238,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function assertRawSitemapLinks() {
$links = func_get_args();
foreach ($links as $link) {
$path = url($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$path = Url::fromUri($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$this->assertRaw($link['loc'], t('Link %path found in the sitemap.', array('%path' => $path)));
}
}
......@@ -245,7 +246,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function assertNoRawSitemapLinks() {
$links = func_get_args();
foreach ($links as $link) {
$path = url($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$path = Url::fromUri($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$this->assertNoRaw($link['loc'], t('Link %path not found in the sitemap.', array('%path' => $path)));
}
}
......@@ -403,7 +404,8 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function verbose($verbose_message, $message = 'Verbose message') {
if ($id = parent::verbose($verbose_message)) {
$url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . get_class($this) . '-' . $id . '.html');
$this->error(l($message, $url, array('attributes' => array('target' => '_blank'))), 'User notice');
$message_url = Url::fromUri($url, array('attributes' => array('target' => '_blank')));
$this->error($this->l($message, $message_url)), 'User notice');
}
}
......
......@@ -13,6 +13,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
/**
* XmlSitemap generator service class.
......@@ -230,13 +231,17 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
if ($url_options['alias']) {
$link['loc'] = $this->getPathAlias($link['loc'], $link['language']->getId());
}
if ($url_options['base_url']) {
$link['loc'] = rtrim($url_options['base_url'], '/') . '/' . ltrim($link['loc'], '/');
}
$link_options = array(
'language' => $link['language'],
'xmlsitemap_link' => $link,
'xmlsitemap_sitemap' => $sitemap,
);
// @todo Add a separate hook_xmlsitemap_link_url_alter() here?
$link_url = url($link['loc'], $link_options + $url_options);
$link['loc'] = empty($link['loc']) ? '<front>' : $link['loc'];
$link_url = Url::fromRoute($link['loc'], [], $link_options + $url_options);
// Skip this link if it was a duplicate of the last one.
// @todo Figure out a way to do this before generation so we can report
......@@ -311,7 +316,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
}
$sitemap = &$context['sandbox']['sitemap'];
$links = $this->generatePage($sitemap, $sitemap->getChunks());
$context['message'] = t('Now generating %sitemap-url.', array('%sitemap-url' => url('sitemap.xml', $sitemap->uri['options'] + array('query' => array('page' => $sitemap->getChunks())))));
$context['message'] = t('Now generating %sitemap-url.', array('%sitemap-url' => Url::fromRoute('xmlsitemap.sitemap_xml', [], $sitemap->uri['options'] + array('query' => array('page' => $sitemap->getChunks())))));
if ($links) {
$sitemap->setLinks($sitemap->getLinks() + $links);
......@@ -344,7 +349,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
$sitemap = xmlsitemap_sitemap_load($smid);
if ($sitemap != NULL && $sitemap->getChunks() > 1) {
$this->generateIndex($sitemap);
$context['message'] = t('Now generating sitemap index %sitemap-url.', array('%sitemap-url' => url('sitemap.xml', $sitemap->uri['options'])));
$context['message'] = t('Now generating sitemap index %sitemap-url.', array('%sitemap-url' => Url::fromRoute('xmlsitemap.sitemap_xml', [], $sitemap->uri['options'])));
}
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\xmlsitemap;
use Drupal\Core\Url;
/**
* Extended class for writing XML sitemap indexes.
*/
......@@ -55,7 +57,7 @@ class XmlSitemapIndexWriter extends XmlSitemapWriter {
for ($i = 1; $i <= $this->sitemap->chunks; $i++) {
$url_options['query']['page'] = $i;
$element = array(
'loc' => url('sitemap.xml', $url_options),
'loc' => Url::fromRoute('xmlsitemap.sitemap_xml', [], $url_options),
// @todo Use the actual lastmod value of the chunk file.
'lastmod' => gmdate($lastmod_format, REQUEST_TIME),
);
......
......@@ -7,6 +7,8 @@
namespace Drupal\xmlsitemap;
use Drupal\Core\Url;
/**
* Extended class for writing XML sitemap files.
*/
......@@ -124,7 +126,7 @@ class XmlSitemapWriter extends \XMLWriter {
* Returns TRUE on success.
*/
public function writeXSL() {
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . url('sitemap.xsl') . '"');
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . Url::fromRoute('xmlsitemap.sitemap_xsl') . '"');
$this->writeRaw(PHP_EOL);
}
......
......@@ -8,6 +8,7 @@
*/
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Url;
/**
* Implements hook_requirements().
......@@ -125,7 +126,7 @@ function xmlsitemap_requirements($phase) {
);
if (\Drupal::state()->get('xmlsitemap_rebuild_needed')) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', array('@link-rebuild' => url('admin/config/search/xmlsitemap/rebuild')));
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', array('@link-rebuild' => Url::fromRoute('xmlsitemap.admin_rebuild')));
}
elseif (\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
if ($max_filesize == 0) {
......@@ -139,7 +140,7 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_WARNING;
}
if ($requirements['xmlsitemap_generated']['severity']) {
$requirements['xmlsitemap_generated']['description'] = $t('The XML cached files are out of date and need to be regenerated. You can <a href="@link-cron">run cron manually</a> to regenerate the sitemap files.', array('@link-cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination()))));
$requirements['xmlsitemap_generated']['description'] = $t('The XML cached files are out of date and need to be regenerated. You can <a href="@link-cron">run cron manually</a> to regenerate the sitemap files.', array('@link-cron' => Url::fromRoute('system.run_cron', [], array('query' => drupal_get_destination()))));
}
}
$anonymous_accout = new AnonymousUserSession();
......@@ -148,7 +149,7 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_user_anonymous_permission'] = array(
'title' => $t('XML sitemap user'),
'value' => $t('Anonymous access to user profiles'),
'description' => $t('In order to list user profile links in the sitemap, the anonymous user must have the <a href="@perm-link"><em>View user profiles</em> permission</a>.', array('@perm-link' => url('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID, array('fragment' => 'module-user')))),
'description' => $t('In order to list user profile links in the sitemap, the anonymous user must have the <a href="@perm-link"><em>View user profiles</em> permission</a>.', array('@perm-link' => Url::fromRoute('entity.user_role.edit_permissions_form', ['user_role' => DRUPAL_ANONYMOUS_RID], array('fragment' => 'module-user')))),
'severity' => REQUIREMENT_ERROR,
);
}
......@@ -295,7 +296,7 @@ function xmlsitemap_install() {
$state_variables = xmlsitemap_state_variables();
\Drupal::state()->setMultiple($state_variables);
\Drupal::state()->set('xmlsitemap_base_url', url(NULL, array('absolute' => TRUE)));
\Drupal::state()->set('xmlsitemap_base_url', (string) Url::fromRoute('<front>', [], array('absolute' => TRUE)));
$context = xmlsitemap_get_current_context();
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
......
......@@ -22,6 +22,7 @@ use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
......@@ -197,7 +198,7 @@ function xmlsitemap_robotstxt() {
$sitemap_storage = \Drupal::entityManager()->getStorage('xmlsitemap');
if ($sitemap = $sitemap_storage->loadByContext()) {
$uri = xmlsitemap_sitemap_uri($sitemap);
$robotstxt[] = 'Sitemap: ' . url($uri['path'], $uri['options']);
$robotstxt[] = 'Sitemap: ' . Url::fromUri($uri['path'], $uri['options']);
return $robotstxt;
}
}
......@@ -1081,7 +1082,7 @@ function xmlsitemap_form_submit_flag_regenerate(array $form, FormStateInterface
}
if ($stored_value != 'not_a_variable' && $stored_value != $value) {
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
drupal_set_message(t('XML sitemap settings have been modified and the files should be regenerated. You can <a href="@run-cron">run cron manually</a> to regenerate the cached files.', array('@run-cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))), 'warning', FALSE);
drupal_set_message(t('XML sitemap settings have been modified and the files should be regenerated. You can <a href="@run-cron">run cron manually</a> to regenerate the cached files.', array('@run-cron' => Url::fromRoute('system.run_cron', [], array('query' => drupal_get_destination())))), 'warning', FALSE);
return;
}
}
......@@ -1144,7 +1145,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array('@bundle' => drupal_strtolower($info['bundle label']), '@link-type' => url($path, array('query' => drupal_get_destination())))),
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array('@bundle' => drupal_strtolower($info['bundle label']), '@link-type' => Url::fromUri($path, array('query' => drupal_get_destination())))),
);
}
......@@ -1935,7 +1936,7 @@ function xmlsitemap_query_xmlsitemap_link_bundle_access_alter(AlterableInterface
*/
function xmlsitemap_link_frontpage_settings(&$form) {
if (\Drupal::currentUser()->hasPermission('administer site configuration')) {
$form['#description'] = t('The front page path can be changed in the <a href="@url-frontpage">site information configuration</a>.', array('@url-frontpage' => url('admin/config/system/site-information')));
$form['#description'] = t('The front page path can be changed in the <a href="@url-frontpage">site information configuration</a>.', array('@url-frontpage' => Url::fromRoute('system.site_information_settings')));
}
$form['xmlsitemap_frontpage_priority'] = array(
'#type' => 'select',
......@@ -1995,7 +1996,8 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
$row = array();
if (drupal_valid_path("admin/config/search/xmlsitemap/settings/$entity/$bundle")) {
$edit_link = xmlsitemap_get_operation_link("admin/config/search/xmlsitemap/settings/$entity/$bundle", array('title' => $bundle_info['label'], 'modal' => TRUE));
$row[] = l($edit_link['title'], $edit_link['href'], $edit_link);
$url = Url::fromUri($edit_link['href'], $edit_link);
$row[] = $this->l($edit_link['title'], $url);
}
else {
// Bundle labels are assumed to be un-escaped input.
......@@ -2328,11 +2330,11 @@ function _xmlsitemap_get_blurb($check_version = TRUE) {
$blurb = FALSE;
if (!$check_version || (($version = _xmlsitemap_get_version()) && preg_match('/dev|unstable|alpha|beta|HEAD/i', $version))) {
$sponsors = array(
l('Symantec', 'http://www.symantec.com/'),
l('WebWise Solutions', 'http://www.webwiseone.com/'),
l('Volacci', 'http://www.volacci.com/'),
l('lanetro', 'http://www.lanetro.com/'),
l('Coupons Dealuxe', 'http://couponsdealuxe.com/'),
$this->l('Symantec', Url::fromUri('http://www.symantec.com/')),
$this->l('WebWise Solutions', Url::fromUri('http://www.webwiseone.com/')),
$this->l('Volacci', Url::fromUri('http://www.volacci.com/')),
$this->l('lanetro', Url::fromUri('http://www.lanetro.com/')),
$this->l('Coupons Dealuxe', Url::fromUri('http://couponsdealuxe.com/')),
);
// Don't extract the following string for translation.
$blurb = '<div class="description"><p>Thank you for helping test the XML sitemap module rewrite. Please consider helping offset developer free time by <a href="http://davereid.chipin.com/">donating</a> or if your company is interested in sponsoring the rewrite or a specific feature, please <a href="http://davereid.net/contact">contact the developer</a>. Thank you to the following current sponsors: ' . implode(', ', $sponsors) . ', and all the individuals that have donated. This message will not be seen in the stable versions.</p></div>';
......@@ -2405,7 +2407,7 @@ function xmlsitemap_check_status() {
$message = t('One or more problems were detected with your XML sitemap configuration: !messages', array('!messages' => drupal_render($messages)));
drupal_set_message($message, 'warning', FALSE);
if (\Drupal::currentUser()->hasPermission('access site reports')) {
drupal_set_message(t('Check the <a href="@status-report">status report</a> for more information.', array('@status-report' => url('admin/reports/status'))), 'warning', FALSE);
drupal_set_message(t('Check the <a href="@status-report">status report</a> for more information.', array('@status-report' => Url::fromRoute('system.status'))), 'warning', FALSE);
}
}
}
......
......@@ -11,6 +11,7 @@ use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
/**
* Builds the list table for all custom links.
......@@ -78,7 +79,7 @@ class XmlSitemapCustomListController extends ControllerBase {
foreach ($result as $link) {
$language = $this->languageManager->getLanguage($link->language);
$row = array();
$row['loc'] = l($link->loc, $link->loc);
$row['loc'] = $this->l($link->loc, Url::fromUri($link->loc));
$row['priority'] = number_format($link->priority, 1);
$row['changefreq'] = $link->changefreq ? drupal_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
if (isset($header['language'])) {
......@@ -115,7 +116,7 @@ class XmlSitemapCustomListController extends ControllerBase {
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No custom links available. <a href="@custom_link">Add custom link</a>', array('@custom_link' => url('admin/config/search/xmlsitemap/custom/add', array('query' => $destination))))
'#empty' => $this->t('No custom links available. <a href="@custom_link">Add custom link</a>', array('@custom_link' => Url::fromRoute('xmlsitemap_custom.add', [], array('query' => $destination))))
);
$build['xmlsitemap_custom_pager'] = array('#theme' => 'pager');
......
......@@ -16,6 +16,7 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\xmlsitemap\XmlSitemapLinkStorageInterface;
/**
......@@ -108,7 +109,7 @@ class XmlSitemapCustomAddForm extends ConfigFormBase {
$form['loc'] = array(
'#type' => 'textfield',
'#title' => t('Path to link'),
'#field_prefix' => url('', array('absolute' => TRUE)),
'#field_prefix' => Url::fromRoute('<front>', [], array('absolute' => TRUE)),
'#default_value' => $link['loc'] ? drupal_get_path_alias($link['loc'], $link['language']) : '',
'#required' => TRUE,
'#size' => 30,
......@@ -148,8 +149,9 @@ class XmlSitemapCustomAddForm extends ConfigFormBase {
'#value' => t('Save'),
'#weight' => 5,
);
$cancel_link = Url::fromRoute('xmlsitemap_custom.list');
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'admin/config/search/xmlsitemap/custom'),
'#markup' => $this->l(t('Cancel'), $cancel_link),
'#weight' => 10,
);
......@@ -179,7 +181,7 @@ class XmlSitemapCustomAddForm extends ConfigFormBase {
}
try {
$client = new Client();
$res = $client->get(url(NULL, array('absolute' => TRUE)) . $link['loc']);
$res = $client->get(Url::fromRoute('<front>', [], array('absolute' => TRUE)) . $link['loc']);
}
catch (ClientException $e) {
$form_state->setErrorByName('loc', t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $link['loc'])));
......
......@@ -17,6 +17,7 @@ use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\xmlsitemap\XmlSitemapLinkStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Provides a form for editing a custom link.
......@@ -127,7 +128,7 @@ class XmlSitemapCustomEditForm extends ConfigFormBase {
$form['loc'] = array(
'#type' => 'textfield',
'#title' => t('Path to link'),
'#field_prefix' => url('', array('absolute' => TRUE)),
'#field_prefix' => Url::fromRoute('<front>', [], array('absolute' => TRUE)),
'#default_value' => $this->custom_link['loc'],
'#required' => TRUE,
'#size' => 30,
......@@ -167,8 +168,9 @@ class XmlSitemapCustomEditForm extends ConfigFormBase {
'#value' => t('Save'),
'#weight' => 5,
);
$cancel_link = Url::fromRoute('xmlsitemap_custom.list');
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'admin/config/search/xmlsitemap/custom'),
'#markup' => l(t('Cancel'), $cancel_link),
'#weight' => 10,
);
......@@ -185,7 +187,7 @@ class XmlSitemapCustomEditForm extends ConfigFormBase {
$form_state->setValue('loc', $link['loc']);
try {
$client = new Client();
$res = $client->get(url(NULL, array('absolute' => TRUE)) . $link['loc']);
$res = $client->get(Url::fromRoute('<front>', [], array('absolute' => TRUE)) . $link['loc']);
}
catch (ClientException $e) {
$form_state->setErrorByName('loc', t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $link['loc'])));
......
......@@ -9,6 +9,7 @@ namespace Drupal\xmlsitemap_engines\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -104,7 +105,7 @@ class XmlSitemapEnginesSettingsForm extends ConfigFormBase {
$form['custom_urls'] = array(
'#type' => 'textarea',
'#title' => t('Custom submission URLs'),
'#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array('absolute' => TRUE))))),
'#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', Url::fromRoute('xmlsitemap.sitemap_xml', [], ['absolute' => TRUE])))),
'#default_value' => $this->config('xmlsitemap_engines.settings')->get('custom_urls'),
'#rows' => 2,
'#wysiwyg' => FALSE
......
......@@ -8,6 +8,7 @@
namespace Drupal\xmlsitemap_engines\Tests;
use Drupal\xmlsitemap\Tests\XmlSitemapTestBase;
use Drupal\Core\Url;
/**
* Test xmlsitemap_engines functionality.
......@@ -50,7 +51,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
// @todo For some reason the test client does not have clean URLs while
// the test runner does, so it causes mismatches in watchdog assertions
// later.
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
$this->submit_url = Url::fromUri('base://ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
/**
......@@ -135,7 +136,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$this->assertText('Invalid URL an-invalid-url.');
$this->assertNoText('The configuration options have been saved.');
$url = url('ping', array('absolute' => TRUE));
$url = Url::fromUri('base://ping', array('absolute' => TRUE));
$edit = array('custom_urls' => $url);
$this->drupalPostForm('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
......@@ -145,9 +146,9 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$this->assertText(t('The configuration options have been saved.'));
$this->submitEngines();
$url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE)));
$url = xmlsitemap_engines_prepare_url($this->submit_url, Url::fromRoute('xmlsitemap.sitemap_xml', [], array('absolute' => TRUE)));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '200')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => url('sitemap.xml', array('absolute' => TRUE)))));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => Url::fromRoute('xmlsitemap.sitemap_xml', [], array('absolute' => TRUE)))));
}
}
......@@ -2,6 +2,7 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
/**
* Implements hook_xmlsitemap_engine_info().
......@@ -18,7 +19,7 @@ function xmlsitemap_engines_test_xmlsitemap_engine_info() {
* Implements hook_xmlsitemap_engine_info_alter().
*/
function xmlsitemap_engines_test_xmlsitemap_engine_info_alter(&$engines) {
$engines['simpletest']['url'] = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
$engines['simpletest']['url'] = Url::fromUri('base://ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
function xmlsitemap_engines_test_pinged() {
......
......@@ -3,6 +3,7 @@
use Drupal\Core\Routing\RouteMatchInterface;
use GuzzleHttp\Exception\RequestException;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
/**
* Implements hook_hook_info().
......@@ -117,7 +118,7 @@ function xmlsitemap_engines_submit_engines(array $smids = array()) {
*/
function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
foreach ($sitemaps as $sitemap) {
$sitemap_url = url($sitemap->uri['path'], $sitemap->uri['options']);
$sitemap_url = Url::fromUri($sitemap->uri['path'], $sitemap->uri['options']);
$submit_url = xmlsitemap_engines_prepare_url($url, $sitemap_url);
try {
$request = \Drupal::httpClient()->get($submit_url);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment