Skip to content

Conversation

@joomdonation
Copy link
Contributor

@joomdonation joomdonation commented Dec 4, 2025

Pull Request for Issue # .

Summary of Changes

This pull request introduces a new utility method to the Joomla\CMS\Table\Table class:

  • getData() – returns the data of the current table record as an associative array. It is needed because developers currently lack a simple and consistent way to retrieve all field values from a Table object. They have to use workarounds such as ArrayHelper::fromObject, get_object_vars or CMSHelper getRowData, CMSHelper getDataObject. Having this method will make make it easier to receive the data from Table object.

Testing Instructions

As this is a new method, I do not really know how to give testing instructions. Maybe it would require maintainer code review?

Actual result BEFORE applying this Pull Request

Expected result AFTER applying this Pull Request

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

Comment on lines +1984 to +1994
public function getData(): array
{
$data = [];

foreach ($this->getFields() as $field) {
$fieldName = $field->Field;
$data[$fieldName] = $this->{$fieldName} ?? null;
}

return $data;
}
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed? ArrayHelper::fromObject should do the same? or do I miss something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if the client code need data from the Table object, the Table class should provide a method to offer that data. We should not have to rely on a helper method from an outside to get necessary data. Having a method like this would be more developer friendly than the other workarounds

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel it is strange that we do not offer this method inside the Table class to expose the data to client code and leave each developer do it in his own way:

  • get_object_vars
  • ArrayHelper::fromObject
  • CMSHelper getRowData
  • CMSHelper getDataObject

Just name a few. Also, please note that the method returns only the actual database columns, in a stable and predictable way while the other methods such as get_object_vars or ArrayHelper::fromObject can return other public properties added to the class. The class itself is the best to provide the data, not from an outsider like this one https://github.com/joomla/joomla-cms/blob/6.1-dev/libraries/src/Helper/CMSHelper.php#L101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants