Move hook to event

Created on 23 August 2023, about 1 year ago
Updated 29 July 2024, 4 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

Fixed

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 about 1 year 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.
  • Merge request !6Issue #3382887: Move hook to event β†’ (Merged) created by ddavisboxleitner
  • πŸ‡ΊπŸ‡Έ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 about 1 year ago
  • Status changed to RTBC about 1 year 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
    7 months ago
    Total: 146s
    #162547
  • Pipeline finished with Skipped
    4 months ago
    #224904
  • Status changed to Fixed 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Merged MR 6.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024