Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
X
xmlsitemap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
xmlsitemap
Commits
0918c391
Commit
0918c391
authored
May 02, 2016
by
amateescu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unneeded entity storage class.
parent
9304f57c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
66 deletions
+47
-66
src/Controller/XmlSitemapController.php
src/Controller/XmlSitemapController.php
+2
-1
src/Entity/XmlSitemap.php
src/Entity/XmlSitemap.php
+17
-1
src/Tests/XmlSitemapTestBase.php
src/Tests/XmlSitemapTestBase.php
+2
-1
src/XmlSitemapInterface.php
src/XmlSitemapInterface.php
+19
-6
src/XmlSitemapStorage.php
src/XmlSitemapStorage.php
+0
-28
src/XmlSitemapStorageInterface.php
src/XmlSitemapStorageInterface.php
+0
-24
xmlsitemap.module
xmlsitemap.module
+7
-5
No files found.
src/Controller/XmlSitemapController.php
View file @
0918c391
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\xmlsitemap\Controller
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -68,7 +69,7 @@ class XmlSitemapController extends ControllerBase {
* is set.
*/
public
function
renderSitemapXml
()
{
$sitemap
=
$this
->
entityManager
->
getStorage
(
'xmlsitemap'
)
->
loadByContext
();
$sitemap
=
XmlSitemap
::
loadByContext
();
if
(
!
$sitemap
)
{
throw
new
NotFoundHttpException
();
}
...
...
src/Entity/XmlSitemap.php
View file @
0918c391
...
...
@@ -12,7 +12,6 @@ use Drupal\xmlsitemap\XmlSitemapInterface;
* id = "xmlsitemap",
* label = @Translation("XmlSitemap"),
* handlers = {
* "storage" = "Drupal\xmlsitemap\XmlSitemapStorage",
* "list_builder" = "Drupal\xmlsitemap\XmlSitemapListBuilder",
* "form" = {
* "add" = "Drupal\xmlsitemap\Form\XmlSitemapForm",
...
...
@@ -189,4 +188,21 @@ class XmlSitemap extends ConfigEntityBase implements XmlSitemapInterface {
return
$this
;
}
/**
* {@inheritdoc}
*/
public
static
function
loadByContext
(
array
$context
=
NULL
)
{
if
(
!
isset
(
$context
))
{
$context
=
xmlsitemap_get_current_context
();
}
$sitemaps
=
static
::
loadMultiple
();
foreach
(
$sitemaps
as
$sitemap
)
{
if
(
$sitemap
->
context
==
$context
)
{
return
$sitemap
;
}
}
return
NULL
;
}
}
src/Tests/XmlSitemapTestBase.php
View file @
0918c391
...
...
@@ -4,6 +4,7 @@ namespace Drupal\xmlsitemap\Tests;
use
Drupal\simpletest\WebTestBase
;
use
Drupal\Core\Url
;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
/**
* Helper test class with some added functions for testing.
...
...
@@ -145,7 +146,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
=
$this
->
entityManager
->
getStorage
(
'xmlsitemap'
)
->
loadByContext
(
$context
);
$sitemap
=
XmlSitemap
::
loadByContext
(
$context
);
if
(
!
$sitemap
)
{
return
$this
->
fail
(
'Could not load sitemap by context.'
);
}
...
...
src/XmlSitemapInterface.php
View file @
0918c391
...
...
@@ -60,7 +60,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the id of the sitemap.
*
* @param string id
* @param string
$
id
* The sitemap id.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -71,7 +71,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the label of the sitemap.
*
* @param string label
* @param string
$
label
* The sitemap label.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -82,7 +82,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the number of chunks.
*
* @param string chunks
* @param string
$
chunks
* The number of chunks.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -93,7 +93,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the number of links.
*
* @param string links
* @param string
$
links
* The number of links.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -104,7 +104,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the maximum file size of the sitemap.
*
* @param string max_filesize
* @param string
$
max_filesize
* The maximum file size.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -115,7 +115,7 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
/**
* Sets the context for the sitemap.
*
* @param string context
* @param string
$
context
* The context.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
...
...
@@ -133,4 +133,17 @@ interface XmlSitemapInterface extends ConfigEntityInterface {
* The class instance that this method is called on.
*/
public
function
setUpdated
(
$updated
);
/**
* Returns the sitemap with the context specified as parameter.
*
* @param array $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.
*
* @return \Drupal\xmlsitemap\XmlSitemapInterface
* Sitemap with the specified context or NULL.
*/
public
static
function
loadByContext
(
array
$context
=
NULL
);
}
src/XmlSitemapStorage.php
deleted
100644 → 0
View file @
9304f57c
<?php
namespace
Drupal\xmlsitemap
;
use
Drupal\Core\Config\Entity\ConfigEntityStorage
;
/**
* Defines a handler class for xmlsitemap entities.
*/
class
XmlSitemapStorage
extends
ConfigEntityStorage
implements
XmlSitemapStorageInterface
{
/**
* {@inheritdoc}
*/
public
function
loadByContext
(
array
$context
=
NULL
)
{
if
(
!
isset
(
$context
))
{
$context
=
xmlsitemap_get_current_context
();
}
$sitemaps
=
$this
->
loadMultiple
();
foreach
(
$sitemaps
as
$sitemap
)
{
if
(
$sitemap
->
context
==
$context
)
{
return
$sitemap
;
}
}
return
NULL
;
}
}
src/XmlSitemapStorageInterface.php
deleted
100644 → 0
View file @
9304f57c
<?php
namespace
Drupal\xmlsitemap
;
use
Drupal\Core\Config\Entity\ConfigEntityStorageInterface
;
/**
* Defines a common interface for xmlsitemap entity handler classes.
*/
interface
XmlSitemapStorageInterface
extends
ConfigEntityStorageInterface
{
/**
* Returns the sitemap with the context specified as parameter.
*
* @param array $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.
*
* @return Drupal\xmlsitemap\XmlSitemapInterface
* Sitemap with the specified context or NULL.
*/
public
function
loadByContext
(
array
$context
=
NULL
);
}
xmlsitemap.module
View file @
0918c391
...
...
@@ -8,10 +8,10 @@
* @file
* Main file for the xmlsitemap module.
*/
use
Drupal\Component\Utility\Crypt
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\xmlsitemap\XmlSitemapInterface
;
use
Drupal\Component\Utility\SafeMarkup
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Core\Render\Element
;
use
Drupal\Core\Entity\EntityForm
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -22,10 +22,13 @@ 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\Language\LanguageInterface
;
use
Drupal\Core\Url
;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
use
Drupal\xmlsitemap\XmlSitemapInterface
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpFoundation\Response
;
use
Drupal\Component\Utility\Unicode
;
/**
* The maximum number of links in one sitemap chunk file.
...
...
@@ -214,8 +217,7 @@ function xmlsitemap_modules_uninstalled(array $modules) {
* Implements hook_robotstxt().
*/
function
xmlsitemap_robotstxt
()
{
$sitemap_storage
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'xmlsitemap'
);
if
(
$sitemap
=
$sitemap_storage
->
loadByContext
())
{
if
(
$sitemap
=
XmlSitemap
::
loadByContext
())
{
$uri
=
xmlsitemap_sitemap_uri
(
$sitemap
);
$robotstxt
[]
=
'Sitemap: '
.
Url
::
fromUri
(
$uri
[
'path'
],
$uri
[
'options'
])
->
toString
();
return
$robotstxt
;
...
...
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