Commit 0918c391 authored by amateescu's avatar amateescu

Remove unneeded entity storage class.

parent 9304f57c
......@@ -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();
}
......
......@@ -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;
}
}
......@@ -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.');
}
......
......@@ -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);
}
<?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;
}
}
<?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);
}
......@@ -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;
......
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