@@ -955,7 +955,7 @@ public function initDinamicData()
955
955
956
956
/**
957
957
* Prepare all additional data
958
- * @param null $fields
958
+ * @param null|array $fields
959
959
* @return array
960
960
*/
961
961
public function getDynamicData ($ fields = null )
@@ -977,30 +977,37 @@ public function getDynamicData($fields = null)
977
977
];
978
978
979
979
foreach ($ keys as $ key ) {
980
- $ method = 'get ' . str_replace (
981
- '_ ' ,
982
- '' ,
983
- ucwords ($ key , '_ ' )
984
- );
985
- $ data [$ key ] = $ this ->$ method ();
980
+ if (null === $ fields || array_key_exists ($ key , $ fields )) {
981
+ $ method = 'get ' . str_replace (
982
+ '_ ' ,
983
+ '' ,
984
+ ucwords ($ key , '_ ' )
985
+ );
986
+ $ data [$ key ] = $ this ->$ method ();
987
+ }
986
988
}
987
989
988
- if (array_key_exists ('tags ' , $ fields )) {
990
+ if (null === $ fields || array_key_exists ('tags ' , $ fields )) {
989
991
$ tags = [];
990
992
foreach ($ this ->getRelatedTags () as $ tag ) {
991
993
$ tags [] = $ tag ->getDynamicData ();
992
994
}
993
995
$ data ['tags ' ] = $ tags ;
994
996
}
995
997
998
+ /* Do not use check for null === $fields here
999
+ * this checks is used for REST, and related data was not provided via reset */
996
1000
if (array_key_exists ('related_posts ' , $ fields )) {
997
1001
$ relatedPosts = [];
998
1002
foreach ($ this ->getRelatedPosts () as $ relatedPost ) {
999
- $ relatedPosts [] = $ relatedPost ->getDynamicData ($ fields );
1003
+ $ relatedPosts [] = $ relatedPost ->getDynamicData (
1004
+ $ fields ['related_posts ' ]
1005
+ );
1000
1006
}
1001
1007
$ data ['related_posts ' ] = $ relatedPosts ;
1002
1008
}
1003
1009
1010
+ /* Do not use check for null === $fields here */
1004
1011
if (array_key_exists ('related_products ' , $ fields )) {
1005
1012
$ relatedProducts = [];
1006
1013
foreach ($ this ->getRelatedProducts () as $ relatedProduct ) {
@@ -1009,16 +1016,18 @@ public function getDynamicData($fields = null)
1009
1016
$ data ['related_products ' ] = $ relatedProducts ;
1010
1017
}
1011
1018
1012
- if (array_key_exists ('categories ' , $ fields )) {
1019
+ if (null === $ fields || array_key_exists ('categories ' , $ fields )) {
1013
1020
$ categories = [];
1014
1021
foreach ($ this ->getParentCategories () as $ category ) {
1015
1022
$ categories [] = $ category ->getDynamicData ();
1016
1023
}
1017
1024
$ data ['categories ' ] = $ categories ;
1018
1025
}
1019
1026
1020
- if (array_key_exists ('author ' , $ fields ) && $ author = $ this ->getAuthor ()) {
1021
- $ data ['author ' ] = $ author ->getDynamicData ();
1027
+ if (null === $ fields || array_key_exists ('author ' , $ fields )) {
1028
+ if ($ author = $ this ->getAuthor ()) {
1029
+ $ data ['author ' ] = $ author ->getDynamicData ();
1030
+ }
1022
1031
}
1023
1032
1024
1033
return $ data ;
0 commit comments