diff --git a/backend/composer.json b/backend/composer.json index 510bf43..3b9808d 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -32,7 +32,8 @@ }, "autoload": { "psr-4": { - "modules\\": "modules/" + "modules\\": "modules/", + "backend\\": "." } }, "config": { diff --git a/backend/config/app.php b/backend/config/app.php index 385f401..3047579 100644 --- a/backend/config/app.php +++ b/backend/config/app.php @@ -24,4 +24,8 @@ return [ 'id' => App::env('CRAFT_APP_ID') ?: 'CraftCMS', + 'modules' => [ + 'authorinfo' => modules\authorinfo\Module::class, + ], + 'bootstrap' => ['authorinfo'], ]; diff --git a/backend/modules/authorinfo/Module.php b/backend/modules/authorinfo/Module.php new file mode 100644 index 0000000..5431d36 --- /dev/null +++ b/backend/modules/authorinfo/Module.php @@ -0,0 +1,100 @@ +adminUser === null) { + $this->adminUser = User::find() + ->admin(true) + ->status(null) + ->orderBy(['elements.id' => SORT_ASC]) + ->one(); + + if ($this->adminUser) { + Craft::info( + "Found admin user: ID: {$this->adminUser->id}, Name: {$this->adminUser->fullName}", + __METHOD__ + ); + } else { + Craft::warning('No admin user found', __METHOD__); + } + } + + return $this->adminUser; + } + + /** + * Handle the DefineGqlTypeFields event + */ + public function handleDefineGqlTypeFields(DefineGqlTypeFieldsEvent $event): void + { + if ($event->typeName !== 'EntryInterface') { + return; + } + + $event->fields['authorId'] = [ + 'name' => 'authorId', + 'type' => Type::int(), + 'description' => 'The entry author\'s ID', + 'resolve' => function($source) { + try { + if ($source->getSection()->type === 'single') { + return $this->getAdminUser()?->id; + } + return $source->authorId; + } catch (\Throwable $e) { + Craft::error("Error resolving authorId: {$e->getMessage()}", __METHOD__); + return null; + } + } + ]; + + $event->fields['authorName'] = [ + 'name' => 'authorName', + 'type' => Type::string(), + 'description' => 'The entry author\'s name', + 'resolve' => function($source) { + try { + if ($source->getSection()->type === 'single') { + return $this->getAdminUser()?->fullName; + } + return $source->getAuthor()?->fullName; + } catch (\Throwable $e) { + Craft::error("Error resolving authorName: {$e->getMessage()}", __METHOD__); + return null; + } + } + ]; + } +} diff --git a/frontend/app.vue b/frontend/app.vue index 38c2695..82edc16 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -8,7 +8,6 @@ const graphql = useGraphQL() const { data: globalsData } = await useAsyncData('globals', async () => { try { const result = await graphql.query(GLOBALS_QUERY) - console.log('GraphQL result:', result) // Debug log return { global: result?.globalEntries?.[0] || {}, pages: result?.pagesEntries || [] diff --git a/frontend/components/alert.vue b/frontend/components/alert.vue index 7a08526..b4205a5 100644 --- a/frontend/components/alert.vue +++ b/frontend/components/alert.vue @@ -14,7 +14,7 @@ diff --git a/frontend/pages/guestbook.vue b/frontend/pages/guestbook.vue index ca0897a..4250d43 100644 --- a/frontend/pages/guestbook.vue +++ b/frontend/pages/guestbook.vue @@ -1,11 +1,13 @@