From b6829fb1d7bc85d336e573bf1b04a02768f90ed8 Mon Sep 17 00:00:00 2001
From: Franck Deroche <defr@ows.fr>
Date: Fri, 13 May 2016 17:59:29 +0200
Subject: [PATCH] Bug #2724833 by DeFr: Processor weights incorrectly used

---
 src/Entity/Index.php             | 4 ++--
 src/Form/IndexProcessorsForm.php | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Entity/Index.php b/src/Entity/Index.php
index 6484160..0b135a2 100644
--- a/src/Entity/Index.php
+++ b/src/Entity/Index.php
@@ -559,8 +559,8 @@ class Index extends ConfigEntityBase implements IndexInterface {
     $processor_weights = array();
     foreach ($processors as $name => $processor) {
       if ($processor->supportsStage($stage)) {
-        if (!empty($processor_settings[$name]['settings']['weights'][$stage])) {
-          $processor_weights[$name] = $processor_settings[$name]['settings']['weights'][$stage];
+        if (isset($this->processor_settings[$name]['settings']['weights'][$stage])) {
+          $processor_weights[$name] = $this->processor_settings[$name]['settings']['weights'][$stage];
         }
         else {
           $processor_weights[$name] = $processor->getDefaultWeight($stage);
diff --git a/src/Form/IndexProcessorsForm.php b/src/Form/IndexProcessorsForm.php
index a610efc..5eb6f92 100644
--- a/src/Form/IndexProcessorsForm.php
+++ b/src/Form/IndexProcessorsForm.php
@@ -169,7 +169,8 @@ class IndexProcessorsForm extends EntityForm {
     foreach ($processors_by_stage as $stage => $processors) {
       /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */
       foreach ($processors as $processor_id => $processor) {
-        $weight = $processor->getDefaultWeight($stage);
+        $config = $processor->getConfiguration();
+        $weight = isset($config['weights'][$stage]) ? $config['weights'][$stage]  : $processor->getDefaultWeight();
         if ($processor->isHidden()) {
           $form['processors'][$processor_id]['weights'][$stage] = array(
             '#type' => 'value',
-- 
1.9.1

