1717use Pimcore \Model ;
1818use Pimcore \Model \DataObject \AbstractObject ;
1919use Pimcore \Model \DataObject \ClassDefinition ;
20+ use Pimcore \Model \DataObject \ClassDefinition \Data ;
2021use Pimcore \Model \DataObject \Classificationstore ;
2122use Pimcore \Model \DataObject \Concrete ;
2223use Pimcore \Model \DataObject \Objectbrick ;
@@ -182,21 +183,27 @@ public static function getData(AbstractObject $object, ?array $fields = null, ?s
182183 }
183184
184185 // because the key for the classification store has not a direct getter, you have to check separately if the data is inheritable
185- if (str_starts_with ($ key , '~ ' )) {
186- $ curClassAttributeValue = $ data [$ key ] ?? null ;
187- $ isValueEmpty = is_array ($ curClassAttributeValue ) ? empty ($ curClassAttributeValue ['value ' ] ?? null ) : empty ($ curClassAttributeValue );
188-
189- if ($ isValueEmpty ) {
190- $ type = $ keyParts [1 ];
191-
192- if ($ type === 'classificationstore ' ) {
193- if (!empty ($ inheritedData = self ::getInheritedData ($ object , $ key , $ requestedLanguage ))) {
194- $ data [$ dataKey ] = $ inheritedData ['value ' ];
195- $ data ['inheritedFields ' ][$ dataKey ] = ['inherited ' => $ inheritedData ['parent ' ]->getId () != $ object ->getId (), 'objectid ' => $ inheritedData ['parent ' ]->getId ()];
196- }
186+ if (
187+ str_starts_with ($ key , '~ ' ) &&
188+ ($ keyParts [1 ] ?? null ) === 'classificationstore '
189+ ) {
190+ $ fieldDef = self ::getClassificationStoreFieldDefinition ($ key );
191+ $ value = self ::normalizeValue ($ data [$ key ]);
192+
193+ if ($ fieldDef ->isEmpty ($ value )) {
194+ $ inheritedData = static ::getInheritedData ($ object , $ key , $ requestedLanguage );
195+
196+ if (!empty ($ inheritedData )) {
197+ $ parent = $ inheritedData ['parent ' ];
198+ $ data [$ dataKey ] = $ inheritedData ['value ' ];
199+ $ data ['inheritedFields ' ][$ dataKey ] = [
200+ 'inherited ' => $ parent ->getId () !== $ object ->getId (),
201+ 'objectid ' => $ parent ->getId (),
202+ ];
197203 }
198204 }
199205 }
206+
200207 if ($ needLocalizedPermissions ) {
201208 if (!$ user ->isAdmin ()) {
202209 $ locale = \Pimcore::getContainer ()->get (LocaleServiceInterface::class)->findLocale ();
@@ -355,17 +362,9 @@ protected static function getInheritedData(Concrete $object, string $key, string
355362 return [];
356363 }
357364
358- $ inheritedValue = self ::getStoreValueForObject ($ parent , $ key , $ requestedLanguage );
359- if (
360- (!is_array ($ inheritedValue ) && $ inheritedValue !== null ) ||
361- (
362- is_array ($ inheritedValue ) &&
363- (
364- array_is_list ($ inheritedValue ) || //for table field types
365- !empty ($ inheritedValue ['value ' ] ?? null )
366- )
367- )
368- ) {
365+ $ inheritedValue = self ::normalizeValue (self ::getStoreValueForObject ($ parent , $ key , $ requestedLanguage ));
366+
367+ if (!static ::getClassificationStoreFieldDefinition ($ key )->isEmpty ($ inheritedValue )) {
369368 return [
370369 'parent ' => $ parent ,
371370 'value ' => $ inheritedValue ,
@@ -374,4 +373,37 @@ protected static function getInheritedData(Concrete $object, string $key, string
374373
375374 return self ::getInheritedData ($ parent , $ key , $ requestedLanguage );
376375 }
376+
377+ /**
378+ * The actual data could be a plain array for tables,
379+ * an associative array for RGB or Quantity Value where the value is a key.
380+ *
381+ */
382+ private static function normalizeValue (mixed $ data ): mixed
383+ {
384+ if (is_array ($ data )) {
385+ if (array_is_list ($ data )) {
386+ return $ data ;
387+ }
388+ if (array_key_exists ('value ' , $ data )) {
389+ return $ data ['value ' ];
390+ }
391+ }
392+
393+ return $ data ;
394+ }
395+
396+ protected static function getClassificationStoreFieldDefinition (string $ key ): Data
397+ {
398+ $ keyParts = explode ('~ ' , $ key );
399+ $ groupKeyId = explode ('- ' , $ keyParts [3 ]);
400+
401+ $ keyid = (int ) $ groupKeyId [1 ];
402+
403+ $ keyConfig = Model \DataObject \Classificationstore \KeyConfig::getById ($ keyid );
404+ $ type = $ keyConfig ->getType ();
405+ $ definition = json_decode ($ keyConfig ->getDefinition (), true );
406+
407+ return \Pimcore \Model \DataObject \Classificationstore \Service::getFieldDefinitionFromJson ($ definition , $ type );
408+ }
377409}
0 commit comments