Commit 6d0973a2 authored by gbyte.co's avatar gbyte.co

Improve plugin interface

parent d66b0bec
......@@ -85,7 +85,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getData() {
protected function getDataSets() {
$arbitrary_links = [];
$this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links);
return array_values($arbitrary_links);
......@@ -94,7 +94,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getPathData($path_data) {
return $path_data;
protected function processDataSet($data_set) {
return $data_set;
}
}
......@@ -97,7 +97,7 @@ class CustomUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getData() {
protected function getDataSets() {
$this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE);
return array_values($this->generator->getCustomLinks());
......@@ -106,36 +106,36 @@ class CustomUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getPathData($data) {
protected function processDataSet($data_set) {
// todo: Change to different function, as this also checks if current user has access. The user however varies depending if process was started from the web interface or via cron/drush. Use getUrlIfValidWithoutAccessCheck()?
if (!$this->pathValidator->isValid($data['path'])) {
if (!$this->pathValidator->isValid($data_set['path'])) {
// if (!(bool) $this->pathValidator->getUrlIfValidWithoutAccessCheck($data['path'])) {
$this->logger->m(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE,
['@path' => $data['path'], '@custom_paths_url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/custom'])
['@path' => $data_set['path'], '@custom_paths_url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/custom'])
->display('warning', 'administer sitemap settings')
->log('warning');
return FALSE;
}
if ($this->batchSettings['remove_duplicates'] && $this->pathProcessed($data['path'])) {
if ($this->batchSettings['remove_duplicates'] && $this->pathProcessed($data_set['path'])) {
return FALSE;
}
$url_object = Url::fromUserInput($data['path'], ['absolute' => TRUE]);
$url_object = Url::fromUserInput($data_set['path'], ['absolute' => TRUE]);
$entity = $this->entityHelper->getEntityFromUrlObject($url_object);
$path_data = [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime')
? date_iso8601($entity->getChangedTime()) : NULL,
'priority' => isset($data['priority']) ? $data['priority'] : NULL,
'changefreq' => !empty($data['changefreq']) ? $data['changefreq'] : NULL,
'priority' => isset($data_set['priority']) ? $data_set['priority'] : NULL,
'changefreq' => !empty($data_set['changefreq']) ? $data_set['changefreq'] : NULL,
'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId')
? $this->getImages($entity->getEntityTypeId(), $entity->id())
: [],
'meta' => [
'path' => $data['path'],
'path' => $data_set['path'],
]
];
......
......@@ -15,7 +15,7 @@ class EntityUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getData() {
protected function getDataSets() {
$data_sets = [];
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
foreach ($this->generator->getBundleSettings() as $entity_type_name => $bundles) {
......@@ -45,11 +45,11 @@ class EntityUrlGenerator extends UrlGeneratorBase {
*/
public function generate() {
foreach ($this->getData() as $entity_info) {
foreach ($this->getDataSets() as $entity_info) {
foreach ($this->getBatchIterationElements($entity_info) as $entity_id => $entity) {
$this->setCurrentId($entity_id);
$path_data = $this->getPathData($entity);
$path_data = $this->processDataSet($entity);
if (!$path_data) {
continue;
}
......@@ -62,7 +62,7 @@ class EntityUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getPathData($entity) {
protected function processDataSet($entity) {
$entity_id = $entity->id();
$entity_type_name = $entity->getEntityTypeId();
......
......@@ -339,23 +339,23 @@ abstract class UrlGeneratorBase extends PluginBase implements PluginInspectionIn
}
/**
* @return mixed
* @return array
*/
abstract protected function getData();
abstract protected function getDataSets();
/**
* @param $path_data
* @param $data_set
* @return array
*/
abstract protected function getPathData($path_data);
abstract protected function processDataSet($data_set);
/**
* Called by batch.
*/
public function generate() {
foreach ($this->getBatchIterationElements($this->getData()) as $id => $data) {
foreach ($this->getBatchIterationElements($this->getDataSets()) as $id => $data_set) {
$this->setCurrentId($id);
$path_data = $this->getPathData($data);
$path_data = $this->processDataSet($data_set);
if (!$path_data) {
continue;
}
......
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