Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6590d1d
Merge branch '4.2-dev' of https://github.com/joomla/joomla-cms into 4…
Hackwar Aug 8, 2022
4d9f49a
Merge branch '4.3-dev' of https://github.com/joomla/joomla-cms into 4…
Hackwar Aug 30, 2022
f831120
Finder: Add custom fields to search index
Hackwar Aug 31, 2022
dc0d3fb
Codestyle and language string improvement
Hackwar Aug 31, 2022
4b71d98
Merge branch '4.3-dev' of https://github.com/joomla/joomla-cms into 4…
Hackwar Oct 23, 2022
cc17996
Checking if customfields are enabled for this component
Hackwar Oct 23, 2022
d959885
Using constants instead of magic numbers
Hackwar Oct 23, 2022
803ff10
Adding note to update Smart Search index after editing
Hackwar Nov 7, 2022
660ef19
Merge branch '4.3-dev' of https://github.com/joomla/joomla-cms into 4…
Hackwar Nov 7, 2022
92c0ee1
Merge branch '4.3-dev' into 4.2-finder-customfields
Hackwar Nov 9, 2022
a8e5d85
Merge branch '4.3-dev' into 4.2-finder-customfields
Hackwar Nov 11, 2022
725829e
Merge branch '4.3-dev' into 4.2-finder-customfields
Hackwar Nov 16, 2022
e680d65
Merge branch '4.3-dev' into 4.2-finder-customfields
richard67 Jan 6, 2023
6e48091
Merge branch '4.3-dev' into 4.2-finder-customfields
richard67 Jan 22, 2023
58a6893
Merge branch '4.3-dev' into 4.2-finder-customfields
Hackwar Jan 30, 2023
06d7c7f
Merge branch '4.3-dev' of https://github.com/joomla/joomla-cms into 4…
Hackwar Mar 2, 2023
b99ccb9
Codestyle
Hackwar Mar 2, 2023
8e21744
Merge branch '5.0-dev' into 4.2-finder-customfields
Hackwar Mar 28, 2023
bc7999c
Merge branch '5.0-dev' into 4.2-finder-customfields
HLeithner Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions administrator/components/com_fields/forms/field.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@
<option value="0">JNO</option>
</field>
</fieldset>
<fieldset name="smartsearchoptions" label="COM_FIELDS_FIELD_SMARTSEARCHOPTIONS_HEADING">
<field
name="searchindex"
type="list"
label="COM_FIELDS_FIELD_SEARCHINDEX_LABEL"
default="0"
validate="options"
>
<option value="0">COM_FIELDS_FIELD_SEARCHINDEX_DONT</option>
<option value="1">COM_FIELDS_FIELD_SEARCHINDEX_SEARCHABLE</option>
<option value="2">COM_FIELDS_FIELD_SEARCHINDEX_TAXONOMY</option>
<option value="3">COM_FIELDS_FIELD_SEARCHINDEX_BOTH</option>
</field>
</fieldset>
</fieldset>
</fields>
</form>
33 changes: 33 additions & 0 deletions administrator/components/com_fields/src/Model/FieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public function save($data)
$field = $this->getItem($data['id']);
}

if (
(is_null($field) && $data['params']['searchindex'] > 0)
|| ($field->params['searchindex'] != $data['params']['searchindex'])
|| ($data['params']['searchindex'] > 0 && ($field->state != $data['state'] || $field->access != $data['access']))
) {
Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING'), 'notice');
}

Comment on lines +118 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following PHP warnings now on a clean 5.0-dev branch when installing blog sample data:

PHP Warning:  Undefined array key "searchindex" in /home/richard/lamp/public_html/joomla-cms-5.0-dev/administrator/components/com_fields/src/Model/FieldModel.php on line 119
PHP Warning:  Attempt to read property "params" on null in /home/richard/lamp/public_html/joomla-cms-5.0-dev/administrator/components/com_fields/src/Model/FieldModel.php on line 120
PHP Warning:  Trying to access array offset on value of type null in /home/richard/lamp/public_html/joomla-cms-5.0-dev/administrator/components/com_fields/src/Model/FieldModel.php on line 120
PHP Warning:  Undefined array key "searchindex" in /home/richard/lamp/public_html/joomla-cms-5.0-dev/administrator/components/com_fields/src/Model/FieldModel.php on line 120
PHP Warning:  Undefined array key "searchindex" in /home/richard/lamp/public_html/joomla-cms-5.0-dev/administrator/components/com_fields/src/Model/FieldModel.php on line 121

if (!isset($data['label']) && isset($data['params']['label'])) {
$data['label'] = $data['params']['label'];

Expand Down Expand Up @@ -860,6 +868,31 @@ protected function populateState()
$this->setState('params', $params);
}

/**
* Method to change the published state of one or more records.
*
* @param array &$pks A list of the primary keys to change.
* @param integer $value The value of the published state.
*
* @return boolean True on success.
*
* @since __DEPLOY_VERSION__
*/
public function publish(&$pks, $value = 1)
{
foreach ($pks as $pk) {
$item = $this->getItem($pk);

if ($item->params['searchindex'] > 0) {
Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING'), 'notice');

break;
}
}

return parent::publish($pks, $value);
}

/**
* A protected method to get a set of ordering conditions.
*
Expand Down
1 change: 1 addition & 0 deletions administrator/components/com_fields/tmpl/field/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<legend><?php echo Text::_('JGLOBAL_FIELDSET_PUBLISHING'); ?></legend>
<div>
<?php echo LayoutHelper::render('joomla.edit.publishingdata', $this); ?>
<?php echo $this->form->renderField('searchindexing'); ?>
</div>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
Expand Down
47 changes: 47 additions & 0 deletions administrator/components/com_finder/src/Indexer/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;

Expand All @@ -30,6 +31,11 @@
*/
class Helper
{
public const CUSTOMFIELDS_DONT_INDEX = 0;
public const CUSTOMFIELDS_ADD_TO_INDEX = 1;
public const CUSTOMFIELDS_ADD_TO_TAXONOMY = 2;
public const CUSTOMFIELDS_ADD_TO_BOTH = 3;

/**
* Method to parse input into plain text.
*
Expand Down Expand Up @@ -385,6 +391,47 @@ public static function getContentExtras(Result $item)
return true;
}

/**
* Add custom fields for the item to the Result object
*
* @param Result $item Result object to add the custom fields to
* @param string $context Context of the item in the custom fields
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function addCustomFields(Result $item, $context)
{
if (!ComponentHelper::getParams(strstr($context, '.', true))->get('custom_fields_enable', 1)) {
return;
}

$obj = new \stdClass();
$obj->id = $item->id;

$fields = FieldsHelper::getFields($context, $obj, true);

foreach ($fields as $field) {
$searchindex = $field->params->get('searchindex', 0);

// We want to add this field to the search index
if ($searchindex == self::CUSTOMFIELDS_ADD_TO_INDEX || $searchindex == self::CUSTOMFIELDS_ADD_TO_BOTH) {
$name = 'jsfield_' . $field->name;
$item->$name = $field->value;
$item->addInstruction(Indexer::META_CONTEXT, $name);
}

// We want to add this field as a taxonomy
if (
($searchindex == self::CUSTOMFIELDS_ADD_TO_TAXONOMY || $searchindex == self::CUSTOMFIELDS_ADD_TO_BOTH)
&& $field->value
) {
$item->addTaxonomy($field->title, $field->value, $field->state, $field->access, $field->language);
}
}
}

/**
* Method to process content text using the onContentPrepare event trigger.
*
Expand Down
7 changes: 7 additions & 0 deletions administrator/language/en-GB/com_fields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ COM_FIELDS_FIELD_RENDER_CLASS_LABEL="Display Class"
COM_FIELDS_FIELD_RENDEROPTIONS_HEADING="Display Options"
COM_FIELDS_FIELD_REQUIRED_LABEL="Required"
COM_FIELDS_FIELD_SAVE_SUCCESS="Field saved"
COM_FIELDS_FIELD_SEARCHINDEX_BOTH="Make searchable and add as taxonomy"
COM_FIELDS_FIELD_SEARCHINDEX_DONT="Don't make searchable"
COM_FIELDS_FIELD_SEARCHINDEX_LABEL="Search Index"
COM_FIELDS_FIELD_SEARCHINDEX_SEARCHABLE="Make searchable"
COM_FIELDS_FIELD_SEARCHINDEX_TAXONOMY="Add as taxonomy"
COM_FIELDS_FIELD_SHOWLABEL_DESC="Show or Hide the label when the field displays."
COM_FIELDS_FIELD_SHOWLABEL_LABEL="Label"
COM_FIELDS_FIELD_SHOWON_DESC="Conditionally show or hide the field depending on the value of other fields."
COM_FIELDS_FIELD_SHOWON_LABEL="Showon Attribute"
COM_FIELDS_FIELD_SMARTSEARCHOPTIONS_HEADING="Smart Search"
COM_FIELDS_FIELD_SUFFIX_LABEL="Suffix"
COM_FIELDS_FIELD_TYPE_LABEL="Type"
COM_FIELDS_FIELD_USE_GLOBAL="Use settings from Plugin"
Expand Down Expand Up @@ -94,6 +100,7 @@ COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING="You need to create standar
COM_FIELDS_ONLY_USE_IN_SUBFORM="- Use in Subform -"
COM_FIELDS_ONLY_USE_IN_SUBFORM_ANY="Any Form"
COM_FIELDS_ONLY_USE_IN_SUBFORM_SUBFORM="Only in Subform"
COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING="Please note, that your changes in the Custom Fields Manager might require you to rebuild the index of Smart Search."
COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED="The <a href=\"%s\">System - Fields</a> plugin is disabled. Custom fields will not display until you enable this plugin."
COM_FIELDS_VIEW_FIELD_ADD_TITLE="%s: New Field"
COM_FIELDS_VIEW_FIELD_EDIT_TITLE="%s: Edit Field"
Expand Down
1 change: 1 addition & 0 deletions plugins/finder/contacts/src/Extension/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ protected function index(Result $item)

// Get content extras.
Helper::getContentExtras($item);
Helper::addCustomFields($item, 'com_contact.contact');

// Index the item.
$this->indexer->index($item);
Expand Down
1 change: 1 addition & 0 deletions plugins/finder/content/src/Extension/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ protected function index(Result $item)

// Get content extras.
Helper::getContentExtras($item);
Helper::addCustomFields($item, 'com_content.article');

// Index the item.
$this->indexer->index($item);
Expand Down