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

Improve plugin interface

parent d66b0bec
...@@ -85,7 +85,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase { ...@@ -85,7 +85,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function getData() { protected function getDataSets() {
$arbitrary_links = []; $arbitrary_links = [];
$this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links); $this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links);
return array_values($arbitrary_links); return array_values($arbitrary_links);
...@@ -94,7 +94,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase { ...@@ -94,7 +94,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function getPathData($path_data) { protected function processDataSet($data_set) {
return $path_data; return $data_set;
} }
} }
...@@ -97,7 +97,7 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -97,7 +97,7 @@ class CustomUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function getData() { protected function getDataSets() {
$this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE); $this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE);
return array_values($this->generator->getCustomLinks()); return array_values($this->generator->getCustomLinks());
...@@ -106,36 +106,36 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -106,36 +106,36 @@ class CustomUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @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()? // 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'])) { // if (!(bool) $this->pathValidator->getUrlIfValidWithoutAccessCheck($data['path'])) {
$this->logger->m(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE, $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') ->display('warning', 'administer sitemap settings')
->log('warning'); ->log('warning');
return FALSE; return FALSE;
} }
if ($this->batchSettings['remove_duplicates'] && $this->pathProcessed($data['path'])) { if ($this->batchSettings['remove_duplicates'] && $this->pathProcessed($data_set['path'])) {
return FALSE; 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); $entity = $this->entityHelper->getEntityFromUrlObject($url_object);
$path_data = [ $path_data = [
'url' => $url_object, 'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime') 'lastmod' => method_exists($entity, 'getChangedTime')
? date_iso8601($entity->getChangedTime()) : NULL, ? date_iso8601($entity->getChangedTime()) : NULL,
'priority' => isset($data['priority']) ? $data['priority'] : NULL, 'priority' => isset($data_set['priority']) ? $data_set['priority'] : NULL,
'changefreq' => !empty($data['changefreq']) ? $data['changefreq'] : NULL, 'changefreq' => !empty($data_set['changefreq']) ? $data_set['changefreq'] : NULL,
'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId') 'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId')
? $this->getImages($entity->getEntityTypeId(), $entity->id()) ? $this->getImages($entity->getEntityTypeId(), $entity->id())
: [], : [],
'meta' => [ 'meta' => [
'path' => $data['path'], 'path' => $data_set['path'],
] ]
]; ];
......
...@@ -15,7 +15,7 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -15,7 +15,7 @@ class EntityUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function getData() { protected function getDataSets() {
$data_sets = []; $data_sets = [];
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes(); $sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
foreach ($this->generator->getBundleSettings() as $entity_type_name => $bundles) { foreach ($this->generator->getBundleSettings() as $entity_type_name => $bundles) {
...@@ -45,11 +45,11 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -45,11 +45,11 @@ class EntityUrlGenerator extends UrlGeneratorBase {
*/ */
public function generate() { public function generate() {
foreach ($this->getData() as $entity_info) { foreach ($this->getDataSets() as $entity_info) {
foreach ($this->getBatchIterationElements($entity_info) as $entity_id => $entity) { foreach ($this->getBatchIterationElements($entity_info) as $entity_id => $entity) {
$this->setCurrentId($entity_id); $this->setCurrentId($entity_id);
$path_data = $this->getPathData($entity); $path_data = $this->processDataSet($entity);
if (!$path_data) { if (!$path_data) {
continue; continue;
} }
...@@ -62,7 +62,7 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -62,7 +62,7 @@ class EntityUrlGenerator extends UrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function getPathData($entity) { protected function processDataSet($entity) {
$entity_id = $entity->id(); $entity_id = $entity->id();
$entity_type_name = $entity->getEntityTypeId(); $entity_type_name = $entity->getEntityTypeId();
......
...@@ -339,23 +339,23 @@ abstract class UrlGeneratorBase extends PluginBase implements PluginInspectionIn ...@@ -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 * @return array
*/ */
abstract protected function getPathData($path_data); abstract protected function processDataSet($data_set);
/** /**
* Called by batch. * Called by batch.
*/ */
public function generate() { public function generate() {
foreach ($this->getBatchIterationElements($this->getData()) as $id => $data) { foreach ($this->getBatchIterationElements($this->getDataSets()) as $id => $data_set) {
$this->setCurrentId($id); $this->setCurrentId($id);
$path_data = $this->getPathData($data); $path_data = $this->processDataSet($data_set);
if (!$path_data) { if (!$path_data) {
continue; 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