Commit 42154514 authored by Patrick Fey's avatar Patrick Fey Committed by Thomas Seidl
Browse files

Issue #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always...

Issue #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always switch back to previous account.
parent f31bb006
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
- #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always
  switch back to previous account.
- #3365370 by Nick_vh, drunken monkey: Added the .gitlab-ci.yml file.
- #3367647 by arti_parmar, drunken monkey: Fixed unused variables and properties
  left in code.
+7 −3
Original line number Diff line number Diff line
@@ -203,6 +203,10 @@ class RenderedItem extends ProcessorPluginBase {
        if (!isset($configuration['view_mode'][$datasource_id][$bundle])) {
          $unset_view_modes[$field->getFieldIdentifier()] = $field->getLabel();
        }

        // Restore the original user.
        $this->getAccountSwitcher()->switchBack();

        continue;
      }
      $view_mode = (string) $configuration['view_mode'][$datasource_id][$bundle];
@@ -230,10 +234,10 @@ class RenderedItem extends ProcessorPluginBase {
        ];
        $this->logException($e, '%type while trying to render item %item_id with view mode %view_mode for search index %index: @message in %function (line %line of %file).', $variables);
      }
    }

      // Restore the original user.
      $this->getAccountSwitcher()->switchBack();
    }

    // Restore the original theme if themes got switched before.
    $this->getThemeSwitcher()->switchBack($previous_theme);
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ use Drupal\node\NodeInterface;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Plugin\search_api\data_type\value\TextValueInterface;
use Drupal\search_api\Utility\Utility;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;

@@ -29,6 +30,8 @@ use Drupal\user\UserInterface;
 */
class RenderedItemTest extends ProcessorTestBase {

  use UserCreationTrait;

  /**
   * List of nodes which are published.
   *
@@ -161,6 +164,10 @@ class RenderedItemTest extends ProcessorTestBase {
      ->get('search_api.fields_helper')
      ->createField($this->index, 'rendered_item', $field_info);
    $this->index->addField($field);
    $field_1 = \Drupal::getContainer()
      ->get('search_api.fields_helper')
      ->createField($this->index, 'rendered_item_1', $field_info);
    $this->index->addField($field_1);
    $datasources = \Drupal::getContainer()
      ->get('search_api.plugin_helper')
      ->createDatasourcePlugins($this->index);
@@ -227,9 +234,14 @@ class RenderedItemTest extends ProcessorTestBase {
    $items = $this->generateItems($items);

    // Add the processor's field values to the items.
    $admin_account = $this->setUpCurrentUser([], [], TRUE);
    foreach ($items as $item) {
      $this->assertEquals($admin_account->id(), \Drupal::currentUser()->id());
      $this->processor->addFieldValues($item);
      $this->assertEquals($admin_account->id(), \Drupal::currentUser()->id());
    }
    \Drupal::currentUser()->setAccount(User::load(0));
    $this->assertEquals(0, \Drupal::currentUser()->id());

    foreach ($items as $key => $item) {
      list($datasource_id, $entity_id) = Utility::splitCombinedId($key);