diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 672bb37..987ffcd 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -1518,7 +1518,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $processors = $this->getOption('processors', array()); foreach ($dependencies['module'] as $module) { - foreach ($this->getProcessors(FALSE) as $key => $processor) { + foreach ($this->getProcessors() as $key => $processor) { if ($processor->getPluginDefinition()['provider'] == $module) { unset($processors[$key]); $changed = TRUE; @@ -1529,12 +1529,16 @@ class Index extends ConfigEntityBase implements IndexInterface { // Make sure that all enabled processors are notified about the dependencies // that will suddenly be removed and give it time to react to that. - foreach ($this->getProcessors() as $processor) { + /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */ + $processors = $this->getOption('processors', array()); + foreach ($this->getProcessors() as $name => $processor) { $is_processor_changed = $processor->onDependencyRemoval($this, $dependencies); if ($is_processor_changed) { + unset($processors[$name]); $changed = TRUE; } } + $this->setOption('processors', $processors); return $changed; } diff --git a/src/Plugin/ConfigurablePluginBase.php b/src/Plugin/ConfigurablePluginBase.php index 0ea2a32..40a3623 100644 --- a/src/Plugin/ConfigurablePluginBase.php +++ b/src/Plugin/ConfigurablePluginBase.php @@ -10,6 +10,7 @@ namespace Drupal\search_api\Plugin; use Drupal\Core\Entity\DependencyTrait; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\search_api\IndexInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -103,4 +104,13 @@ abstract class ConfigurablePluginBase extends PluginBase implements Configurable return array(); } + /** + * {@inheritdoc} + */ + public function onDependencyRemoval(IndexInterface $index, array $dependencies) { + // By default, we're not reacting to anything and so we should leave + // everything as it was. + return FALSE; + } + } diff --git a/src/Plugin/ConfigurablePluginInterface.php b/src/Plugin/ConfigurablePluginInterface.php index e937f42..d0d5345 100644 --- a/src/Plugin/ConfigurablePluginInterface.php +++ b/src/Plugin/ConfigurablePluginInterface.php @@ -12,6 +12,7 @@ use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\search_api\IndexInterface; /** * Describes a configurable Search API plugin. @@ -35,4 +36,17 @@ interface ConfigurablePluginInterface extends PluginInspectionInterface, Derivat */ public function getDescription(); + /** + * Informs the plugin that entities it depends on will be deleted. + * + * @param \Drupal\search_api\IndexInterface $index + * The index we're being removed from. + * @param array $dependencies + * An array of dependencies + * + * @return bool + * Has something changed? + */ + public function onDependencyRemoval(IndexInterface $index, array $dependencies); + } diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index 90d4d49..707232d 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -174,17 +174,4 @@ interface ProcessorInterface extends IndexPluginInterface { */ public function requiresReindexing(array $old_settings = NULL, array $new_settings = NULL); - /** - * Informs the plugin that entities it depends on will be deleted. - * - * @param \Drupal\search_api\IndexInterface $index - * The index we're being removed from. - * @param array $dependencies - * An array of dependencies - * - * @return bool - * Has something changed? - */ - public function onDependencyRemoval(IndexInterface $index, array $dependencies); - } diff --git a/src/Processor/ProcessorPluginBase.php b/src/Processor/ProcessorPluginBase.php index fbb309b..f873d62 100644 --- a/src/Processor/ProcessorPluginBase.php +++ b/src/Processor/ProcessorPluginBase.php @@ -111,13 +111,4 @@ abstract class ProcessorPluginBase extends IndexPluginBase implements ProcessorI // indexing process. return $this->supportsStage(ProcessorInterface::STAGE_PREPROCESS_INDEX); } - - /** - * {@inheritdoc} - */ - public function onDependencyRemoval(IndexInterface $index, array $dependencies) { - // By default, we're not reacting to anything and so we should leave - // everything as it was. - return FALSE; - } } diff --git a/src/Tests/DependencyRemovalTest.php b/src/Tests/DependencyRemovalTest.php index a88c042..1e28e5d 100644 --- a/src/Tests/DependencyRemovalTest.php +++ b/src/Tests/DependencyRemovalTest.php @@ -94,13 +94,14 @@ class DependencyRemovalTest extends WebTestBase { */ public function testProcessorDependencyRemoval2() { EntityViewMode::create(array('id' => 'node.teaser_test', 'targetEntityType' => 'node'))->save(); + \Drupal::state()->set('search_api_test_processor.remove', TRUE); $this->drupalGet($this->getIndexPath('processors')); - $this->assertText($this->t('Dependency remove processor')); - $this->drupalPostForm(NULL, array('status[dependency_remove_processor]' => 1), $this->t('Save')); + $this->assertText($this->t('Dependency test processor')); + $this->drupalPostForm(NULL, array('status[dependency_test_processor]' => 1), $this->t('Save')); $this->assertResponse(200); $this->assertText($this->t('The indexing workflow was successfully edited.')); - $this->assertFieldChecked('edit-status-dependency-remove-processor'); + $this->assertFieldChecked('edit-status-dependency-test-processor'); $evm = EntityViewMode::load('node.teaser_test'); $evm->delete(); @@ -109,7 +110,7 @@ class DependencyRemovalTest extends WebTestBase { $this->assertResponse(200); $this->drupalGet($this->getIndexPath('processors')); - $this->assertNoFieldChecked('edit-status-dependency-remove-processor'); + $this->assertNoFieldChecked('edit-status-dependency-test-processor'); } /** diff --git a/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml index f942ae4..15f5d25 100644 --- a/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml +++ b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml @@ -19,14 +19,3 @@ plugin.plugin_configuration.search_api_processor.dependency_test_processor: sequence: type: string label: 'Selected field' - -plugin.plugin_configuration.search_api_processor.dependency_remove_processor: - type: mapping - label: 'Dummy remove processor configuration' - mapping: - fields: - type: sequence - label: 'The selected fields' - sequence: - type: string - label: 'Selected field' diff --git a/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyRemoveProcessor.php b/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyRemoveProcessor.php deleted file mode 100644 index 171e99f..0000000 --- a/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyRemoveProcessor.php +++ /dev/null @@ -1,73 +0,0 @@ -addDependency('config', $evm->getEntityType()->getConfigPrefix() . '.' . $evm->id()); - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - return $this->dependencies; - } - - /** - * {@inheritdoc} - */ - public function onDependencyRemoval(IndexInterface $index, array $dependencies) { - $processors = $index->getOption('processors', array()); - unset($processors['dependency_remove_processor']); - $index->setOption('processors', $processors); - return TRUE; - } - -} diff --git a/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyTestProcessor.php b/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyTestProcessor.php index aefeb36..ebaffc7 100644 --- a/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyTestProcessor.php +++ b/tests/search_api_test_processor/src/Plugin/search_api/processor/DependencyTestProcessor.php @@ -30,12 +30,7 @@ class DependencyTestProcessor extends FieldsProcessorPluginBase { /** * {@inheritdoc} */ - protected function process(&$value) { - // We don't touch integers, NULL values or the like. - if (is_string($value)) { - $value .= ' test processor touched this'; - } - } + protected function process(&$value) {} /** * {@inheritdoc} @@ -64,7 +59,7 @@ class DependencyTestProcessor extends FieldsProcessorPluginBase { * {@inheritdoc} */ public function onDependencyRemoval(IndexInterface $index, array $dependencies) { - return FALSE; + return \Drupal::state()->get('search_api_test_processor.remove'); } }