Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
xmlsitemap
Commits
2eb800bd
Commit
2eb800bd
authored
Jul 28, 2014
by
andrei.dincu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2249723
by andrei.dincu: Move xmlsitemap_sitemap_load_by_context() to XmlSitemapStorage
parent
ede8995a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
27 deletions
+47
-27
src/Controller/XmlSitemapController.php
src/Controller/XmlSitemapController.php
+12
-3
src/Tests/XmlSitemapTestBase.php
src/Tests/XmlSitemapTestBase.php
+33
-1
xmlsitemap.module
xmlsitemap.module
+2
-23
No files found.
src/Controller/XmlSitemapController.php
View file @
2eb800bd
...
...
@@ -13,6 +13,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\State\StateInterface
;
use
Drupal\Core\Template\TwigEnvironment
;
use
Drupal\Core\Entity\EntityManagerInterface
;
/**
* Returns responses for xmlsitemap.sitemap_xml and xmlsitemap.sitemap_xsl routes.
...
...
@@ -33,15 +34,23 @@ class XmlSitemapController extends ControllerBase {
*/
protected
$twig
;
/**
* The entity manager object.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected
$entityManager
;
/**
* Constructs a new XmlSitemapController object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public
function
__construct
(
StateInterface
$state
,
TwigEnvironment
$twig
)
{
public
function
__construct
(
StateInterface
$state
,
TwigEnvironment
$twig
,
EntityManagerInterface
$entity_manager
)
{
$this
->
state
=
$state
;
$this
->
twig
=
$twig
;
$this
->
entityManager
=
$entity_manager
;
}
/**
...
...
@@ -49,7 +58,7 @@ class XmlSitemapController extends ControllerBase {
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'state'
),
$container
->
get
(
'twig'
)
$container
->
get
(
'state'
),
$container
->
get
(
'twig'
)
,
$container
->
get
(
'entity.manager'
)
);
}
...
...
@@ -62,7 +71,7 @@ class XmlSitemapController extends ControllerBase {
* The sitemap in XML format or plain text if xmlsitemap_developer_mode flag is set.
*/
public
function
renderSitemapXml
()
{
$sitemap
=
xmlsitemap_sitemap_load_by_c
ontext
();
$sitemap
=
$this
->
entityManager
->
getStorage
(
'xmlsitemap'
)
->
loadByC
ontext
();
if
(
!
$sitemap
)
{
throw
new
NotFoundHttpException
();
}
...
...
src/Tests/XmlSitemapTestBase.php
View file @
2eb800bd
...
...
@@ -15,17 +15,49 @@ use Drupal\simpletest\WebTestBase;
abstract
class
XmlSitemapTestBase
extends
WebTestBase
{
public
static
$modules
=
array
(
'xmlsitemap'
);
/**
* The admin user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected
$admin_user
;
/**
* The state store.
*
* @var \Drupal\Core\State\StateInterface
*/
protected
$state
;
/**
* The xmlsitemap.settings configuration object.
*
* @var \Drupal\Core\Config\Config
*/
protected
$config
;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* The entity manager object.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected
$entityManager
;
public
function
setUp
()
{
array_unshift
(
self
::
$modules
,
'xmlsitemap'
);
parent
::
setUp
();
$this
->
state
=
\
Drupal
::
state
();
$this
->
config
=
\
Drupal
::
configFactory
()
->
get
(
'xmlsitemap.settings'
);
$this
->
moduleHandler
=
\
Drupal
::
moduleHandler
();
$this
->
entityManager
=
\
Drupal
::
entityManager
();
}
public
function
tearDown
()
{
...
...
@@ -78,7 +110,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
* The retrieved HTML string, also available as $this->drupalGetContent()
*/
protected
function
drupalGetSitemap
(
array
$context
=
array
(),
array
$options
=
array
(),
array
$headers
=
array
())
{
$sitemap
=
xmlsitemap_sitemap_load_by_c
ontext
(
$context
);
$sitemap
=
$this
->
entityManager
->
getStorage
(
'xmlsitemap'
)
->
loadByC
ontext
(
$context
);
if
(
!
$sitemap
)
{
return
$this
->
fail
(
'Could not load sitemap by context.'
);
}
...
...
xmlsitemap.module
View file @
2eb800bd
...
...
@@ -202,7 +202,8 @@ function xmlsitemap_modules_disabled(array $modules) {
* Implements hook_robotstxt().
*/
function
xmlsitemap_robotstxt
()
{
if
(
$sitemap
=
xmlsitemap_sitemap_load_by_context
())
{
$sitemap_storage
=
\
Drupal
::
entityManager
()
->
getStorage
(
'xmlsitemap'
);
if
(
$sitemap
=
$sitemap_storage
->
loadByContext
())
{
$uri
=
xmlsitemap_sitemap_uri
(
$sitemap
);
$robotstxt
[]
=
'Sitemap: '
.
url
(
$uri
[
'path'
],
$uri
[
'options'
]);
return
$robotstxt
;
...
...
@@ -321,28 +322,6 @@ function xmlsitemap_sitemap_load_multiple($smids = array(), array $conditions =
return
$sitemaps
;
}
/**
* Load an XML sitemap array from the database based on its context.
*
* @param $context
* An optional XML sitemap context array to use to find the correct XML
* sitemap. If not provided, the current site's context will be used.
*
* @see xmlsitemap_get_current_context()
*/
function
xmlsitemap_sitemap_load_by_context
(
array
$context
=
NULL
)
{
if
(
!
isset
(
$context
))
{
$context
=
xmlsitemap_get_current_context
();
}
$sitemaps
=
\
Drupal
::
entityManager
()
->
getStorage
(
'xmlsitemap'
)
->
loadMultiple
();
foreach
(
$sitemaps
as
$sitemap
)
{
if
(
$sitemap
->
context
==
$context
)
{
return
$sitemap
;
}
}
return
NULL
;
}
/**
* Save changes to an XML sitemap or add a new XML sitemap.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment