You are here

public function ParagraphBundle::addFieldValues in Search API Sort Priority 8

Adds the values of properties defined by this processor to the item.

Parameters

\Drupal\search_api\Item\ItemInterface $item: The item whose field values should be added.

Overrides ProcessorPluginBase::addFieldValues

File

src/Plugin/search_api/processor/ParagraphBundle.php, line 76

Class

ParagraphBundle
Adds customized sort priority by Paragraph Bundle.

Namespace

Drupal\search_api_sort_priority\Plugin\search_api\processor

Code

public function addFieldValues(ItemInterface $item) {

  // Get default weight.
  $weight = $this->configuration['weight'];

  // TODO We are only working with paragraphs for now.
  if ($item
    ->getDatasource()
    ->getEntityTypeId() == 'paragraph') {
    $bundle_type = $item
      ->getDatasource()
      ->getItemBundle($item
      ->getOriginalObject());

    // Get the weight assigned to content type.
    if ($this->configuration['sorttable'][$bundle_type]['weight']) {
      $weight = $this->configuration['sorttable'][$bundle_type]['weight'];
    }

    // Set the weight on all the configured fields.
    $fields = $this
      ->getFieldsHelper()
      ->filterForPropertyPath($item
      ->getFields(), NULL, $this->targetFieldId);
    foreach ($fields as $field) {
      $field
        ->addValue($weight);
    }
  }
}