You are here

public static function XmlSitemap::loadByContext in XML sitemap 8

Same name and namespace in other branches
  1. 2.x src/Entity/XmlSitemap.php \Drupal\xmlsitemap\Entity\XmlSitemap::loadByContext()

Returns the sitemap with the context specified as parameter.

Parameters

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 value

\Drupal\xmlsitemap\XmlSitemapInterface Sitemap with the specified context or NULL.

Overrides XmlSitemapInterface::loadByContext

4 calls to XmlSitemap::loadByContext()
XmlSitemapController::renderSitemapXml in src/Controller/XmlSitemapController.php
Provides the sitemap in XML format.
XmlSitemapRobotsTxtIntegrationTest::testRobotsTxt in tests/src/Functional/XmlSitemapRobotsTxtIntegrationTest.php
Test if sitemap link is included in robots.txt file.
XmlSitemapTestBase::drupalGetSitemap in tests/src/Functional/XmlSitemapTestBase.php
Retrieves an XML sitemap.
xmlsitemap_robotstxt in ./xmlsitemap.module
Implements hook_robotstxt().

File

src/Entity/XmlSitemap.php, line 200

Class

XmlSitemap
Defines the XmlSitemap entity.

Namespace

Drupal\xmlsitemap\Entity

Code

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;
}