|
17 | 17 | use Joomla\CMS\Language\Multilanguage; |
18 | 18 | use Joomla\CMS\Plugin\PluginHelper; |
19 | 19 | use Joomla\CMS\Table\Table; |
| 20 | +use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; |
20 | 21 | use Joomla\Registry\Registry; |
21 | 22 | use Joomla\String\StringHelper; |
22 | 23 |
|
@@ -432,6 +433,43 @@ public static function getContentExtras(Result $item) |
432 | 433 | return true; |
433 | 434 | } |
434 | 435 |
|
| 436 | + /** |
| 437 | + * Add custom fields for the item to the Result object |
| 438 | + * |
| 439 | + * @param Result $item Result object to add the custom fields to |
| 440 | + * @param string $context Context of the item in the custom fields |
| 441 | + * |
| 442 | + * @return void |
| 443 | + * |
| 444 | + * @since __DEPLOY_VERSION__ |
| 445 | + */ |
| 446 | + public static function addCustomFields(Result $item, $context) |
| 447 | + { |
| 448 | + $obj = new \stdClass; |
| 449 | + $obj->id = $item->id; |
| 450 | + |
| 451 | + $fields = FieldsHelper::getFields($context, $obj, true); |
| 452 | + |
| 453 | + foreach ($fields as $field) |
| 454 | + { |
| 455 | + $searchindex = $field->params->get('searchindex', 0); |
| 456 | + |
| 457 | + // We want to add this field to the search index |
| 458 | + if ($searchindex == 1 || $searchindex == 3) |
| 459 | + { |
| 460 | + $name = 'jsfield_' . $field->name; |
| 461 | + $item->$name = $field->value; |
| 462 | + $item->addInstruction(Indexer::META_CONTEXT, $name); |
| 463 | + } |
| 464 | + |
| 465 | + // We want to add this field as a taxonomy |
| 466 | + if (($searchindex == 2 || $searchindex == 3) && $field->value) |
| 467 | + { |
| 468 | + $item->addTaxonomy($field->title, $field->value, $field->state, $field->access, $field->language); |
| 469 | + } |
| 470 | + } |
| 471 | + } |
| 472 | + |
435 | 473 | /** |
436 | 474 | * Method to process content text using the onContentPrepare event trigger. |
437 | 475 | * |
|
0 commit comments