@@ -42,36 +42,40 @@ public function __construct(string $type)
4242 /**
4343 * Get the attributes array.
4444 *
45- * @param array|\stdClass|CMSObject $post The data container
46- * @param array|null $fields The requested fields to be rendered
45+ * @param array|object $post The data container
46+ * @param array|null $fields The requested fields to be rendered
4747 *
4848 * @return array
4949 *
5050 * @since 4.0.0
5151 */
5252 public function getAttributes ($ post , array $ fields = null )
5353 {
54- if (!( $ post instanceof \stdClass) && !( \ is_array ($ post )) && !($ post instanceof CMSObject )) {
54+ if (!\ is_array ($ post ) && !\is_object ($ post )) {
5555 $ message = sprintf (
56- 'Invalid argument for %s. Expected array or %s . Got %s ' ,
56+ 'Invalid argument for %s. Expected array or object . Got %s ' ,
5757 static ::class,
58- CMSObject::class,
5958 \gettype ($ post )
6059 );
6160
6261 throw new \InvalidArgumentException ($ message );
6362 }
6463
65- // The response from a standard ListModel query
66- if ($ post instanceof \stdClass) {
67- $ post = (array ) $ post ;
68- }
69-
70- // The response from a standard AdminModel query also works for Table which extends CMSObject
64+ // The response from a standard AdminModel query also works for legacy objects which extends CMSObject
7165 if ($ post instanceof CMSObject) {
7266 $ post = $ post ->getProperties ();
7367 }
7468
69+ // The object response, from a standard ListModel query
70+ if (\is_object ($ post )) {
71+ $ source = $ post ;
72+ $ post = [];
73+
74+ foreach ($ source as $ p => $ v ) {
75+ $ post [$ p ] = $ v ;
76+ }
77+ }
78+
7579 $ event = new Events \OnGetApiAttributes ('onGetApiAttributes ' , ['attributes ' => $ post , 'context ' => $ this ->type ]);
7680
7781 /** @var Events\OnGetApiAttributes $eventResult */
0 commit comments