Feature PR-6.0-dev Pending

User tests: Successful: Unsuccessful:

avatar CraftException
CraftException
11 Jun 2025

Pull Request for Issue # .

Summary of Changes

Added getField method to FieldsHelper.php to get a single field instead of every field of an item.

Testing Instructions

Actual result BEFORE applying this Pull Request

If you want to get a single field of an item, you have to foreach trough every field, until you found the correct field.

Expected result AFTER applying this Pull Request

You can now just use this function.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

Votes

# of Users Experiencing Issue
0/1
Average Importance Score
5.00

avatar CraftException CraftException - open - 11 Jun 2025
avatar CraftException CraftException - change - 11 Jun 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 11 Jun 2025
Category Administration com_fields
avatar CraftException CraftException - change - 11 Jun 2025
Labels Added: PR-6.0-dev
avatar CraftException CraftException - change - 12 Jun 2025
The description was changed
avatar CraftException CraftException - edited - 12 Jun 2025
avatar CraftException CraftException - change - 17 Jun 2025
Labels Added: Feature
avatar Ruud68
Ruud68 - comment - 20 Jun 2025

Is there a reason why you do not do a $this->getFields(...) and then return the field with Id if it exists?
That would save a lot of (duplicated) code in the new function?

so something like this:

public static function getField(
        $context,
        $fieldId,
        $item = null,
        $prepareValue = false,
        ?object $valueToOverride = null,
        bool $includeSubformFields = false
    ) {
        $fields = $this->getFields($context, $item, $prepareValue, $valuesToOverride, $includeSubformFields);
        $fields = array_column($fields, NULL, 'id');
        return $fields[$fieldId] ?? null;
}

Add a Comment

Login with GitHub to post a comment