Move hook to event

Created on 23 August 2023, 10 months ago
Updated 2 May 2024, about 2 months ago

Problem/Motivation

Search API Solr 4.3 will deprecate hooks.

We use search_api_federated_solr_search_api_solr_documents_alter()

Proposed resolution

Replace hook with and implementation of \Drupal\search_api_solr\Event\PostCreateIndexDocumentsEvent

See https://www.drupal.org/project/search_api_solr/issues/3203375 ✨ Introduce events and deprecate hooks Fixed

πŸ“Œ Task
Status

RTBC

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @agentrickard
  • First commit to issue fork.
  • @elber opened merge request.
  • Status changed to Needs work 10 months ago
  • πŸ‡§πŸ‡·Brazil elber Brazil

    Hi I started to add event, but is missing to dispatch it.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    This is a great start. The missing piece here is that we don't create or own this event, it belongs to search_api_solr.

    See https://www.drupal.org/project/search_api_solr/issues/3203375 ✨ Introduce events and deprecate hooks Fixed

    We need an EventSusbscriber service that response to \Drupal\search_api_solr\Event\PostCreateIndexDocumentsEvent

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States ddavisboxleitner

    I have made an attempt to move the code from search_api_federated_solr_search_api_solr_documents_alter into an event subscriber.

    Importantly, I had to use:
    $documents = $event->getSolariumDocuments();

    To get the list of documents, and at the end of the function I call:
    $event->setSolariumDocuments($documents);

    I was following the annotation in search_api_solr's Event class:

    <?php
    
    namespace Drupal\search_api_solr\Event;
    
    /**
     * Event to be fired after all solarium documents
     * have been created for indexing.
     *
     * @code
     *   // Add a "foo" field with value "bar" to all documents.
     *   $documents = $event->getSolariumDocuments();
     *   foreach ($documents as $document) {
     *     $document->setField('foo', 'bar');
     *   }
     *   $event->setSolariumDocuments($documents):
     * @endcode
     *
     * @Event
     */
    final class PostCreateIndexDocumentsEvent extends AbstractSearchApiItemsSolariumDocumentsEvent {}
  • Status changed to Needs review 10 months ago
  • Status changed to RTBC 10 months ago
  • πŸ‡§πŸ‡·Brazil elber Brazil

    Hi @ddavisboxleitner I reviewed it.

    No bugs found
    Changes applied correctly.

    I'm using drupal 10.1 version and branch 4.x

    Module is ok.

    Moving to RTBC.

  • First commit to issue fork.
  • Pipeline finished with Success
    about 2 months ago
    Total: 146s
    #162547
Production build 0.69.0 2024