-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[6.1] Add getData and supportCheckin methods to Table class #46534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.1-dev
Are you sure you want to change the base?
Conversation
| public function getData(): array | ||
| { | ||
| $data = []; | ||
|
|
||
| foreach ($this->getFields() as $field) { | ||
| $fieldName = $field->Field; | ||
| $data[$fieldName] = $this->{$fieldName} ?? null; | ||
| } | ||
|
|
||
| return $data; | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Pull Request for Issue # .
Summary of Changes
This pull request introduces a new utility method to the
Joomla\CMS\Table\Tableclass: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_varsor 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