@@ -74,18 +74,14 @@ public function loadByAttribute(string $className,
7474 }
7575
7676 if ($ this ->isObjectBrickAttribute ($ attributeName ) === false && $ operator === '= ' && $ identifier !== '' ) {
77- $ getter = 'getBy ' . $ attributeName ;
78- if (empty ($ attributeLanguage ) === false ) {
79- $ element = $ className ::$ getter ($ identifier , $ attributeLanguage , $ limit , 0 , $ objectTypes );
80- } else {
81- if (method_exists ($ className , $ getter )) {
82- $ element = $ className ::$ getter ($ identifier );
83- }
84-
85- if (!$ element ) {
86- $ element = $ className ::$ getter ($ identifier , $ limit , 0 , $ objectTypes );
87- }
88- }
77+ $ element = $ this ->getDataObject (
78+ $ attributeName ,
79+ $ className ,
80+ $ identifier ,
81+ $ attributeLanguage ,
82+ $ limit ,
83+ $ objectTypes
84+ );
8985 } else {
9086 $ queryFieldName = $ attributeName ;
9187 if ($ this ->isObjectBrickAttribute ($ attributeName ) === true ) {
@@ -132,4 +128,25 @@ public function loadByPath(string $identifier,
132128 {
133129 return $ className ::getByPath ($ identifier );
134130 }
131+
132+ private function getDataObject (
133+ string $ attributeName ,
134+ string $ className ,
135+ string $ identifier ,
136+ string $ attributeLanguage ,
137+ int $ limit ,
138+ array $ objectTypes
139+ ): ?ElementInterface {
140+ $ getter = 'getBy ' . $ attributeName ;
141+
142+ if (empty ($ attributeLanguage ) === false ) {
143+ return $ className ::$ getter ($ identifier , $ attributeLanguage , $ limit , 0 , $ objectTypes );
144+ }
145+
146+ if (method_exists ($ className , $ getter )) {
147+ return $ className ::$ getter ($ identifier );
148+ }
149+
150+ return $ className ::$ getter ($ identifier , $ limit , 0 , $ objectTypes );
151+ }
135152}
0 commit comments