Commit 9a7b9123 authored by gbyte.co's avatar gbyte.co

Fix entity generator plugin generating for only one bundle

parent 4ab0d5e2
......@@ -27,4 +27,9 @@ class UrlGenerator extends Plugin {
* @var integer
*/
public $weight;
/**
* @var boolean
*/
public $instantiateForEachDataSet;
}
......@@ -106,11 +106,12 @@ class Batch {
/**
* Adds an operation to the batch.
*
* @param string $plugin_id
* @param $plugin_id
* @param array|null $data_sets
*/
public function addOperation($plugin_id) {
public function addOperation($plugin_id, $data_sets = NULL) {
$this->batch['operations'][] = [
__CLASS__ . '::generate', [$plugin_id, $this->batchSettings],
__CLASS__ . '::generate', [$plugin_id, $data_sets, $this->batchSettings],
];
}
......@@ -118,17 +119,18 @@ class Batch {
* Batch callback function which generates URLs.
*
* @param $plugin_id
* @param array|null $data_sets
* @param array $batch_settings
* @param $context
*
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/
public static function generate($plugin_id, array $batch_settings, &$context) {
public static function generate($plugin_id, $data_sets, array $batch_settings, &$context) {
\Drupal::service('plugin.manager.simple_sitemap.url_generator')
->createInstance($plugin_id)
->setContext($context)
->setBatchSettings($batch_settings)
->generate();
->generate($data_sets);
}
/**
......
......@@ -17,7 +17,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @UrlGenerator(
* id = "arbitrary",
* weight = 20
* weight = 20,
* instantiateForEachDataSet = false
* )
*/
class ArbitraryUrlGenerator extends UrlGeneratorBase {
......@@ -86,7 +87,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getDataSets() {
public function getDataSets() {
$arbitrary_links = [];
$this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links);
return array_values($arbitrary_links);
......
......@@ -19,7 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @UrlGenerator(
* id = "custom",
* weight = 0
* weight = 0,
* instantiateForEachDataSet = false
* )
*/
class CustomUrlGenerator extends UrlGeneratorBase {
......@@ -98,7 +99,7 @@ class CustomUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getDataSets() {
public function getDataSets() {
$this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE);
return array_values($this->generator->getCustomLinks());
......
......@@ -8,7 +8,8 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
*
* @UrlGenerator(
* id = "entity",
* weight = 10
* weight = 10,
* instantiateForEachDataSet = true
* )
*/
class EntityUrlGenerator extends UrlGeneratorBase {
......@@ -16,7 +17,7 @@ class EntityUrlGenerator extends UrlGeneratorBase {
/**
* @inheritdoc
*/
protected function getDataSets() {
public function getDataSets() {
$data_sets = [];
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
foreach ($this->generator->getBundleSettings() as $entity_type_name => $bundles) {
......@@ -41,25 +42,6 @@ class EntityUrlGenerator extends UrlGeneratorBase {
return $data_sets;
}
/**
* @inheritdoc
*/
public function generate() {
foreach ($this->getDataSets() as $entity_info) {
foreach ($this->getBatchIterationElements($entity_info) as $entity_id => $entity) {
$this->setCurrentId($entity_id);
$path_data = $this->processDataSet($entity);
if (!$path_data) {
continue;
}
$this->addUrl($path_data);
}
$this->processSegment();
}
}
/**
* @inheritdoc
*/
......
......@@ -338,7 +338,7 @@ abstract class UrlGeneratorBase extends PluginBase implements PluginInspectionIn
/**
* @return array
*/
abstract protected function getDataSets();
abstract public function getDataSets();
/**
* @param $data_set
......@@ -348,9 +348,12 @@ abstract class UrlGeneratorBase extends PluginBase implements PluginInspectionIn
/**
* Called by batch.
*
* @param array|null $data_sets
*/
public function generate() {
foreach ($this->getBatchIterationElements($this->getDataSets()) as $id => $data_set) {
public function generate($data_sets = NULL) {
$data_sets = NULL !== $data_sets ? $data_sets : $this->getDataSets();
foreach ($this->getBatchIterationElements($data_sets) as $id => $data_set) {
$this->setCurrentId($id);
$path_data = $this->processDataSet($data_set);
if (!$path_data) {
......
......@@ -256,7 +256,14 @@ class Simplesitemap {
});
foreach ($plugins as $plugin) {
$this->batch->addOperation($plugin['id']);
if ($plugin['instantiateForEachDataSet']) {
foreach ($this->urlGeneratorManager->createInstance($plugin['id'])->getDataSets() as $data_sets) {
$this->batch->addOperation($plugin['id'], $data_sets);
}
}
else {
$this->batch->addOperation($plugin['id']);
}
}
$this->batch->start();
......
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