diff --git a/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php b/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php new file mode 100644 index 0000000..1576af8 --- /dev/null +++ b/com_oauthserver/administrator/src/Model/GetItemByIdentifierTrait.php @@ -0,0 +1,49 @@ +getState($this->getName() . '.identifier'); + /** @var \Joomla\CMS\Table\Table $table */ + $table = $this->getTable(); + + if (!empty($identifier)) { + $return = $table->load(['identifier' => $identifier]); + + if ($return === false) { + if (method_exists($table, 'getError') && $table->getError()) { + throw new \RuntimeException($table->getError()); + } + throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST')); + } + } + + // Convert to the CMSObject before adding other data. + $properties = $table->getProperties(true); + $all_properties = $table->getProperties(false); + + if (!empty($all_properties['_jsonEncode'])) { + foreach ($all_properties['$_jsonEncode'] as $prop) { + if (array_key_exists($prop, $properties) && is_string($properties[$prop])) { + $properties[$prop] = json_decode($properties[$prop]); + } + } + } + + return ArrayHelper::toObject($properties, CMSObject::class, true); + } +} \ No newline at end of file