Commit ddcfcdd5 authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Move xmlsitemap_link_* manipulation functions...

Issue #2249723 by andrei.dincu: Move xmlsitemap_link_* manipulation functions from xmlsitemap.module to XmlSitemapLinkStorage service
parent 0154c262
......@@ -14,6 +14,7 @@ use Drupal\Core\State\StateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\xmlsitemap\XmlSitemapLinkStorageInterface;
/**
* Configure xmlsitemap settings for this site.
......@@ -34,6 +35,13 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
*/
protected $formBuilder;
/**
* The xmlsitemap.link_storage service.
*
* @var \Drupal\xmlsitemap\XmlSitemapLinkInterface
*/
protected $linkStorage;
/**
* Constructs a new XmlSitemapSettingsForm object.
*
......@@ -44,10 +52,11 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
* @param \Drupal\Core\Form\FormBuilderInterface $state
* The form builder service.
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, FormBuilderInterface $form_builder) {
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, FormBuilderInterface $form_builder, XmlSitemapLinkStorageInterface $link_storage) {
parent::__construct($config_factory);
$this->state = $state;
$this->formBuilder = $form_builder;
$this->linkStorage = $link_storage;
}
/**
......@@ -55,7 +64,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'), $container->get('state'), $container->get('form_builder')
$container->get('config.factory'), $container->get('state'), $container->get('form_builder'), $container->get('xmlsitemap.link_storage')
);
}
......@@ -230,7 +239,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
$config->set('frontpage_priority', $frontpage_priority);
$config->set('frontpage_changefreq', $frontpage_changefreq);
$config->save();
xmlsitemap_link_save(array('type' => 'frontpage', 'id' => 0, 'loc' => '', 'priority' => $frontpage_priority, 'changefreq' => $frontpage_changefreq));
$this->linkStorage->save(array('type' => 'frontpage', 'id' => 0, 'loc' => '', 'priority' => $frontpage_priority, 'changefreq' => $frontpage_changefreq));
}
$this->state->set('xmlsitemap_developer_mode', $values['xmlsitemap_developer_mode']);
$this->state->set('xmlsitemap_base_url', $values['xmlsitemap_base_url']);
......
......@@ -220,8 +220,8 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$this->assertSitemapLinkValues('node', $node->id(), array('subtype' => 'page2', 'status' => 0, 'priority' => 0.0));
$this->assertSitemapLinkValues('node', $node_old->id(), array('subtype' => 'page2', 'status' => 0, 'priority' => 0.0));
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page'))), 0);
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2'))), 2);
$this->assertEqual(count($this->linkStorage->loadMultiple(array('type' => 'node', 'subtype' => 'page'))), 0);
$this->assertEqual(count($this->linkStorage->loadMultiple(array('type' => 'node', 'subtype' => 'page2'))), 2);
// delete all pages in order to allow content type deletion
$node->delete();
......@@ -229,7 +229,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$this->drupalPostForm('admin/structure/types/manage/page2/delete', array(), t('Delete'));
$this->assertText('The content type Basic page has been deleted.');
$this->assertFalse(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2')), 'Nodes with deleted node type removed from {xmlsitemap}.');
$this->assertFalse($this->linkStorage->loadMultiple(array('type' => 'node', 'subtype' => 'page2')), 'Nodes with deleted node type removed from {xmlsitemap}.');
}
/**
......
......@@ -70,6 +70,13 @@ abstract class XmlSitemapTestBase extends WebTestBase {
*/
protected $languageManager;
/**
* The xmlsitemap link storage handler.
*
* @var \Drupal\xmlsitemap\XmlSitemapLinkStorageInterface
*/
protected $linkStorage;
/**
* {@inheritdoc}
*/
......@@ -81,6 +88,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$this->moduleHandler = \Drupal::moduleHandler();
$this->entityManager = \Drupal::entityManager();
$this->languageManager = \Drupal::languageManager();
$this->linkStorage = \Drupal::service('xmlsitemap.link_storage');
}
/**
......@@ -156,11 +164,11 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
$links = $this->linkStorage->loadMultiple($entity_type);
$link = $links ? reset($links) : FALSE;
}
else {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
}
$this->assertTrue(is_array($link), 'Link loaded.');
return $link;
......@@ -168,28 +176,28 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function assertNoSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
$links = $this->linkStorage->loadMultiple($entity_type);
$link = $links ? reset($links) : FALSE;
}
else {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
}
$this->assertFalse($link, 'Link not loaded.');
return $link;
}
protected function assertSitemapLinkVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
$this->assertTrue($link && $link['access'] && $link['status'], t('Sitemap link @type @id is visible.', array('@type' => $entity_type, '@id' => $entity_id)));
}
protected function assertSitemapLinkNotVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
$this->assertTrue($link && !($link['access'] && $link['status']), t('Sitemap link @type @id is not visible.', array('@type' => $entity_type, '@id' => $entity_id)));
}
protected function assertSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
......@@ -208,7 +216,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
}
protected function assertNotSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$link = $this->linkStorage->load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
......@@ -256,7 +264,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$link += array('loc' => $link['type'] . '-' . $link['id']);
$last_id = max($last_id, $link['id']) + 1;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
return $link;
}
......
......@@ -160,56 +160,56 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
}
/**
* Tests for xmlsitemap_link_save().
* Tests for XmlSitemapLinkStorage::save().
*/
public function testSaveLink() {
$link = array('type' => 'testing', 'id' => 1, 'loc' => 'testing', 'status' => 1);
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['status'] = 0;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
$link['loc'] = 'new_location';
$link['status'] = 1;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.0;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.1;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 1.0;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 1;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
$link['priority'] = 0;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
$link['priority_override'] = 0;
$link['status'] = 1;
xmlsitemap_link_save($link);
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
}
/**
* Tests for xmlsitemap_link_delete().
* Tests for XmlSitemapLinkStorage::delete().
*/
public function testLinkDelete() {
// Add our testing data.
......@@ -220,21 +220,21 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
// Test delete multiple links.
// Test that the regenerate flag is set when visible links are deleted.
$deleted = xmlsitemap_link_delete_multiple(array('loc' => 'testing1'));
$deleted = $this->linkStorage->deleteMultiple(array('loc' => 'testing1'));
$this->assertEqual($deleted, 2);
$this->assertFalse(xmlsitemap_link_load($link1['type'], $link1['id']));
$this->assertFalse(xmlsitemap_link_load($link2['type'], $link2['id']));
$this->assertTrue(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFalse($this->linkStorage->load($link1['type'], $link1['id']));
$this->assertFalse($this->linkStorage->load($link2['type'], $link2['id']));
$this->assertTrue($this->linkStorage->load($link3['type'], $link3['id']));
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$deleted = xmlsitemap_link_delete($link3['type'], $link3['id']);
$deleted = $this->linkStorage->delete($link3['type'], $link3['id']);
$this->assertEqual($deleted, 1);
$this->assertFalse(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFalse($this->linkStorage->load($link3['type'], $link3['id']));
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
}
/**
* Tests for xmlsitemap_link_update_multiple().
* Tests for \Drupal\xmlsitemap\XmlSitemapLinkStorageInterface::updateMultiple().
*/
public function testUpdateLinks() {
// Add our testing data.
......@@ -248,7 +248,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
// 2 | testing | group1 | '' | 1 | 1 | 0.5
// 3 | testing | group2 | '' | 1 | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('status' => 0), array('type' => 'testing', 'subtype' => 'group1', 'status_override' => 0));
$updated = $this->linkStorage->updateMultiple(array('status' => 0), array('type' => 'testing', 'subtype' => 'group1', 'status_override' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
......@@ -256,7 +256,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
// 2 | testing | group1 | '' | 0 | 0.5
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('priority' => 0.0), array('type' => 'testing', 'subtype' => 'group1', 'priority_override' => 0));
$updated = $this->linkStorage->updateMultiple(array('priority' => 0.0), array('type' => 'testing', 'subtype' => 'group1', 'priority_override' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
......@@ -264,7 +264,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
// 2 | testing | group1 | '' | 0 | 0.0
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('subtype' => 'group2'), array('type' => 'testing', 'subtype' => 'group1'));
$updated = $this->linkStorage->updateMultiple(array('subtype' => 'group2'), array('type' => 'testing', 'subtype' => 'group1'));
$this->assertEqual($updated, 2);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
......@@ -272,7 +272,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
// 2 | testing | group2 | '' | 0 | 0.0
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('status' => 1), array('type' => 'testing', 'subtype' => 'group2', 'status_override' => 0, 'status' => 0));
$updated = $this->linkStorage->updateMultiple(array('status' => 1), array('type' => 'testing', 'subtype' => 'group2', 'status_override' => 0, 'status' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
......@@ -312,7 +312,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
xmlsitemap_link_delete($link['type'], $link['id']);
$this->linkStorage->delete($link['type'], $link['id']);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
......
......@@ -15,7 +15,7 @@ use Drupal\Core\State\StateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
/**
* XmlSitemap generator service.
* XmlSitemap generator service class.
*/
class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
......
......@@ -8,19 +8,79 @@
namespace Drupal\xmlsitemap;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a class to save/update/delete/load xmlsitemap links.
* XmlSitemap link storage service class.
*/
class XmlSitemapLinkStorage {
class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
/**
* Saves or updates a sitemap link.
* The state store.
*
* @param $link
* An array with a sitemap link.
* @var \Drupal\Core\State\StateInterface
*/
public static function linkSave(array $link) {
protected $state;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a XmlSitemapGeneratorService object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state handler.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler) {
$this->state = $state;
$this->moduleHandler = $module_handler;
}
public function create(EntityInterface $entity) {
if (!isset($entity->xmlsitemap)) {
$entity->xmlsitemap = array();
if ($entity->id() && $link = $this->load($entity->getEntityTypeId(), $entity->id())) {
$entity->xmlsitemap = $link;
}
}
$settings = xmlsitemap_link_bundle_load($entity->getEntityTypeId(), $entity->bundle());
$uri = $entity->url();
$entity->xmlsitemap += array(
'type' => $entity->getEntityTypeId(),
'id' => (string) $entity->id(),
'subtype' => $entity->bundle(),
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => $settings['priority'],
'priority_default' => $settings['priority'],
'priority_override' => 0,
'changefreq' => isset($settings['changefreq']) ? $settings['changefreq'] : 0
);
$url = $entity->url();
// The following values must always be checked because they are volatile.
$entity->xmlsitemap['loc'] = $uri;
$entity->xmlsitemap['access'] = isset($url) ? 1 : 0;
$language = $entity->language();
$entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
return $entity->xmlsitemap;
}
/**
* {@inheritdoc}
*/
public function save(array $link) {
$link += array(
'access' => 1,
'status' => 1,
......@@ -34,7 +94,7 @@ class XmlSitemapLinkStorage {
);
// Allow other modules to alter the link before saving.
\Drupal::moduleHandler()->alter('xmlsitemap_link', $link);
$this->moduleHandler->alter('xmlsitemap_link', $link);
// Temporary validation checks.
// @todo Remove in final?
......@@ -49,39 +109,27 @@ class XmlSitemapLinkStorage {
$existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, array(':type' => $link['type'], ':id' => $link['id']))->fetchAssoc();
// Check if this is a changed link and set the regenerate flag if necessary.
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLink($link, $existing, TRUE);
if (!$this->state->get('xmlsitemap_regenerate_needed')) {
$this->checkChangedLink($link, $existing, TRUE);
}
// Save the link and allow other modules to respond to the link being saved.
if ($existing) {
drupal_write_record('xmlsitemap', $link, array('type', 'id'));
\Drupal::moduleHandler()->invokeAll('xmlsitemap_link_update', array($link));
$this->moduleHandler->invokeAll('xmlsitemap_link_update', array($link));
}
else {
drupal_write_record('xmlsitemap', $link);
\Drupal::moduleHandler()->invokeAll('xmlsitemap_link_insert', array($link));
$result = drupal_write_record('xmlsitemap', $link);
$this->moduleHandler->invokeAll('xmlsitemap_link_insert', array($link));
}
return $link;
}
/**
* Check if there is sitemap link is changed from the existing data.
*
* @param $link
* An array of the sitemap link.
* @param $original_link
* An optional array of the existing data. This should only contain the
* fields necessary for comparison. If not provided the existing data will be
* loaded from the database.
* @param $flag
* An optional boolean that if TRUE, will set the regenerate needed flag if
* there is a match. Defaults to FALSE.
* @return
* TRUE if the link is changed, or FALSE otherwise.
* {@inheritdoc}
*/
public static function checkChangedLink(array $link, $original_link = NULL, $flag = FALSE) {
public function checkChangedLink(array $link, $original_link = NULL, $flag = FALSE) {
$changed = FALSE;
if ($original_link === NULL) {
......@@ -107,24 +155,16 @@ class XmlSitemapLinkStorage {
}
if ($changed && $flag) {
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
}
/**
* Check if there is a visible sitemap link given a certain set of conditions.
*
* @param $conditions
* An array of values to match keyed by field.
* @param $flag
* An optional boolean that if TRUE, will set the regenerate needed flag if
* there is a match. Defaults to FALSE.
* @return
* TRUE if there is a visible link, or FALSE otherwise.
* {@inheritdoc}
*/
public static function checkChangedLinks(array $conditions = array(), array $updates = array(), $flag = FALSE) {
public function checkChangedLinks(array $conditions = array(), array $updates = array(), $flag = FALSE) {
// If we are changing status or access, check for negative current values.
$conditions['status'] = (!empty($updates['status']) && empty($conditions['status'])) ? 0 : 1;
$conditions['access'] = (!empty($updates['access']) && empty($conditions['access'])) ? 0 : 1;
......@@ -138,43 +178,24 @@ class XmlSitemapLinkStorage {
$changed = $query->execute()->fetchField();
if ($changed && $flag) {
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
}
/**
* Delete a specific sitemap link from the database.
*
* If a visible sitemap link was deleted, this will automatically set the
* regenerate needed flag.
*
* @param $entity_type
* A string with the entity type.
* @param $entity_id
* An integer with the entity ID.
* @return
* The number of links that were deleted.
* {@inheritdoc}
*/
public static function linkDelete($entity_type, $entity_id) {
public function delete($entity_type, $entity_id) {
$conditions = array('type' => $entity_type, 'id' => $entity_id);
return self::linkDeleteMultiple($conditions);
return $this->deleteMultiple($conditions);
}
/**
* Delete multiple sitemap links from the database.
*
* If visible sitemap links were deleted, this will automatically set the
* regenerate needed flag.
*
* @param $conditions
* An array of conditions on the {xmlsitemap} table in the form
* 'field' => $value.
* @return
* The number of links that were deleted.
* {@inheritdoc}
*/
public static function linkDeleteMultiple(array $conditions) {
public function deleteMultiple(array $conditions) {
// Because this function is called from sub-module uninstall hooks, we have
// to manually check if the table exists since it could have been removed
// in xmlsitemap_uninstall().
......@@ -183,8 +204,8 @@ class XmlSitemapLinkStorage {
return FALSE;
}
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLinks($conditions, array(), TRUE);
if (!$this->state->get('xmlsitemap_regenerate_needed')) {
$this->checkChangedLinks($conditions, array(), TRUE);
}
// @todo Add a hook_xmlsitemap_link_delete() hook invoked here.
......@@ -198,23 +219,13 @@ class XmlSitemapLinkStorage {
}
/**
* Perform a mass update of sitemap data.
*
* If visible links are updated, this will automatically set the regenerate
* needed flag to TRUE.
*
* @param $updates
* An array of values to update fields to, keyed by field name.
* @param $conditions
* An array of values to match keyed by field.
* @return
* The number of links that were updated.
* {@inheritdoc}
*/
public static function linkUpdateMultiple($updates = array(), $conditions = array(), $check_flag = TRUE) {
public function updateMultiple($updates = array(), $conditions = array(), $check_flag = TRUE) {
// If we are going to modify a visible sitemap link, we will need to set
// the regenerate needed flag.
if ($check_flag && !\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLinks($conditions, $updates, TRUE);
if ($check_flag && !$this->state->get('xmlsitemap_regenerate_needed')) {
$this->checkChangedLinks($conditions, $updates, TRUE);
}
// Process updates.
......@@ -228,30 +239,17 @@ class XmlSitemapLinkStorage {
}
/**
* Load a specific sitemap link from the database.
*
* @param $entity_type
* A string with the entity type.
* @param $entity_id
* An integer with the entity ID.
* @return
* A sitemap link (array) or FALSE if the conditions were not found.
* {@inheritdoc}
*/
public static function linkLoad($entity_type, $entity_id) {
$link = self::linkLoadMultiple(array('type' => $entity_type, 'id' => $entity_id));
public function load($entity_type, $entity_id) {
$link = $this->loadMultiple(array('type' => $entity_type, 'id' => $entity_id));
return $link ? reset($link) : FALSE;
}
/**
* Load sitemap links from the database.
*
* @param $conditions
* An array of conditions on the {xmlsitemap} table in the form
* 'field' => $value.
* @return
* An array of sitemap link arrays.
* {@inheritdoc}
*/
public static function linkLoadMultiple(array $conditions = array()) {
public function loadMultiple(array $conditions = array()) {
$query = db_select('xmlsitemap');
$query->fields('xmlsitemap');
......
<?php
/**
* @file
* Definition of Drupal\xmlsitemap\XmlSitemapLinkStorageInterface.
*/
namespace Drupal\xmlsitemap;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides an interface defining a XmlSitemapLinkStorage service.
*/
interface XmlSitemapLinkStorageInterface {
/**
* Create a sitemap link from an entity.
*
* The link will be saved as $entity->xmlsitemap.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity whose sitemap link will be created.
*/