Case: an entity type can have an entityreference field referencing the file entity type. Currently it's not possible to index contents of such a field.

Also, it would be good to have support for the Search API Entity Translation module.

CommentFileSizeAuthor
#5 support_for-2617228-5.patch6.56 KBfjgarlin
#2 2617228-2.patch7.03 KBleksat

Comments

Leksat created an issue. See original summary.

leksat’s picture

Assigned: leksat » Unassigned
Status: Active » Needs review
StatusFileSize
new7.03 KB

Here is the patch providing both features.

leksat’s picture

BTW, the patch is made on base of 7.x-1.6 version, and may not apply to the 7.x-1.x branch.

grimreaper’s picture

Status: Needs review » Needs work

Hello,

Thanks for the patch, here is my review.

  1. +++ b/contrib/search_api_attachments_entityreference/README.txt
    @@ -8,11 +8,13 @@ Example:
    - field_references: an Entityreference field, that is containing some file fields:
    + field_references: an Entityreference field, that references a node containing
    

    This line generate a conflict with the dev version.

  2. +++ b/contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc
    @@ -27,14 +27,26 @@ class SearchApiAttachmentsEntityreferenceAlterSettings extends SearchApiAttachme
    +      $entity_type = (strpos($this->index->item_type, 'search_api_et_') === 0) ? substr($this->index->item_type, 14) : $this->index->item_type;
    

    Why 14? Please add a comment.

  3. +++ b/contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc
    @@ -27,14 +27,26 @@ class SearchApiAttachmentsEntityreferenceAlterSettings extends SearchApiAttachme
    +          if (is_object($referenced_entities)) {
    +            // The wrapper can return either an array of entity objects, or a
    +            // single entity object. We want the result be an array always.
    +            $referenced_entities = array($referenced_entities);
    +          }
    

    Fixed in the dev version and so these lines generate a conflict.

  4. +++ b/contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc
    @@ -42,28 +54,8 @@ class SearchApiAttachmentsEntityreferenceAlterSettings extends SearchApiAttachme
    -                    // Limit to the max number of value per field.
    -                    if (isset($this->options['number_indexed']) && $this->options['number_indexed'] != '0' && count($files) > $this->options['number_indexed']) {
    -                      $files = array_slice($files, 0, $this->options['number_indexed']);
    -                    }
    -                    foreach ($files as $file) {
    -                      // Private file restriction.
    -                      if (!$this->is_temporary($file) && !($this->options['excluded_private'] && $this->is_private($file))) {
    -                        // Extension restriction.
    -                        if (!in_array($file['filemime'], $exclude)) {
    -                          // File size restriction.
    -                          $file_size_errors = file_validate_size((object) $file, $max_file_size);
    -                          if (empty($file_size_errors)) {
    -                            $attachments = 'attachments_' . $file_field['field_name'];
    -                            if (isset($item->{$attachments})) {
    -                              $item->{$attachments} .= ' ' . $this->getFileContent($file);
    -                            }
    -                            else {
    -                              $item->{$attachments} = $this->getFileContent($file);
    -                            }
    -                          }
    -                        }
    -                      }
    

    Thanks for extracting that in a function. Please can you do the same thing for the other module/sub-modules.

  5. +++ b/contrib/search_api_attachments_entityreference/includes/callback_attachments_entityreference_settings.inc
    @@ -88,7 +80,7 @@ class SearchApiAttachmentsEntityreferenceAlterSettings extends SearchApiAttachme
    +      $fields = $this->getFileFields() + $this->getEntityReferenceFields();
    

    I am skeptical on this line. Entityreference fields don't target in general file entities. Maybe we willneed to be more precise.

In addition, I don't think it is a good idea to mix the entity translation and the file reference throught entityreference into the same patch.

fjgarlin’s picture

Status: Needs work » Needs review
StatusFileSize
new6.56 KB

Hi,

I run into this issue too. As the module has evolved since this issue was created, I created a patch based on @leksat patch and some of the feedback from @grimreaper but applied to the new version of the module.

I tested it and it works.
The patch is attached.

izus’s picture

Hi,
i rebased the patch in #5 as it was not applying
i will merge it
Thanks all

  • izus committed 26c6ed9 on 7.x-1.x authored by fjgarlin
    Issue #2617228 by Leksat, fjgarlin, Grimreaper, izus: Support for:...
izus’s picture

Status: Needs review » Fixed

there was a good catch from Grimreaper's review in #4

Thanks for extracting that in a function. Please can you do the same thing for the other module/sub-modules.

i let that point to anyone wanting to open an issue for that and contribute a patch for it

This is now merged Thanks all :)

Status: Fixed » Closed (fixed)

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