[BUG]: Custom Field - DatabaseInterface has not been registered #1285

Closed
opened 2026-02-06 13:49:02 +00:00 by Hubertus Meyer · 3 comments

What Happened?

After Adding a Custom Field extending "List", i got the Error "Resource 'PREFIX\Component\COMPONENT\Administrator\Field\DatabaseInterface' has not been registered with the container."

After manually adding the line "use Joomla\Database\DatabaseInterface;" to the Top of the field file, it worked as intended.

So either i forgot to add the line somewhere else in JCB or the compiler forgot to add the line automaticly.

Steps to reproduce the Bug

  • Create Custom Field extending "List", getting data from another AdminView Database Table.
  • Compile component
  • Install component
  • Go to the AdminView of the component
  • Try to Add New Item
  • Get Error: "Resource 'PREFIX\Component\COMPONENT\Administrator\Field\DatabaseInterface' has not been registered with the container."

Which Joomla version are you compiling in?

6.02

Which PHP version are you compiling in?

8.3.30

Which Joomla versions are you targeting?

6.0.2

Which PHP version are you targeting?

8.3.30

Which Web server is JCB running on?

Apache/2.4.66 (Debian)

Which Relational Database is JCB running on?

mysql 8.0.45

Which OS is JCB running on?

Joomla Docker Image running on MacOS 26.2 (25C56)

Which JCB version are you using?

6.1.4-beta6

Where in JCB did this issue occur?

Installation of a component, Compiler(admin_view), Field(admin_view)

On which browsers did you encounter the issue?

Safari

Additional Comments

No response

### What Happened? After Adding a Custom Field extending "List", i got the Error "Resource 'PREFIX\Component\COMPONENT\Administrator\Field\DatabaseInterface' has not been registered with the container." After manually adding the line "use Joomla\Database\DatabaseInterface;" to the Top of the field file, it worked as intended. So either i forgot to add the line somewhere else in JCB or the compiler forgot to add the line automaticly. ### Steps to reproduce the Bug - Create Custom Field extending "List", getting data from another AdminView Database Table. - Compile component - Install component - Go to the AdminView of the component - Try to Add New Item - Get Error: "Resource 'PREFIX\Component\COMPONENT\Administrator\Field\DatabaseInterface' has not been registered with the container." ### Which Joomla version are you compiling in? 6.02 ### Which PHP version are you compiling in? 8.3.30 ### Which Joomla versions are you targeting? 6.0.2 ### Which PHP version are you targeting? 8.3.30 ### Which Web server is JCB running on? Apache/2.4.66 (Debian) ### Which Relational Database is JCB running on? mysql 8.0.45 ### Which OS is JCB running on? Joomla Docker Image running on MacOS 26.2 (25C56) ### Which JCB version are you using? 6.1.4-beta6 ### Where in JCB did this issue occur? Installation of a component, Compiler(admin_view), Field(admin_view) ### On which browsers did you encounter the issue? Safari ### Additional Comments _No response_
Hubertus Meyer added the Bug label 2026-02-06 13:49:02 +00:00
Author

Additional Info: i used the pregunfigured php code in the custom field get-options method. Inside this default configuration DatabaseInterface is referenced without any namespace.
To prevent, that i always need to add the use Joomla\Database\DatabaseInterface; line manually to the file, i changed the reference inside the get-options method in the field editing view to Joomla\Database\DatabaseInterface which works fine.

So either the use has to be added to the header or the default value for a custom field shoul be updated.

Additional Info: i used the pregunfigured php code in the custom field get-options method. Inside this default configuration DatabaseInterface is referenced without any namespace. To prevent, that i always need to add the use Joomla\Database\DatabaseInterface; line manually to the file, i changed the reference inside the get-options method in the field editing view to Joomla\Database\DatabaseInterface which works fine. So either the use has to be added to the header or the default value for a custom field shoul be updated.
Owner

Hello @hubmey,

Thank you for bringing this issue to our attention. This is exactly where the Joomla Power system is meant to shine.

To resolve this, please replace the following line:

$db = Factory::getContainer()->get(DatabaseInterface::class);

with:

$db = Joomla___39403062_84fb_46e0_bac4_0023f766e827___Power::getContainer()->get(Joomla___7bd29d76_73c9_4c07_a5da_4f7a32aff78f___Power::class);

During compilation, this will automatically inject the correct Class into your use statements with the proper namespace.

The underlying issue is that the preconfigured code provided in the custom code field is technically correct, but references to Joomla core classes are not being converted to their corresponding JPKs. As a result, the Power system is not loaded correctly.

We will be updating this default code to address this. In the meantime, simply adding the correct JPK keys, as shown above, will ensure that the required Joomla classes are loaded properly.

For more details on how JPKs work in JCB, please refer to the Joomla Powers Repository.

Hello @hubmey, Thank you for bringing this issue to our attention. This is exactly where the Joomla Power system is meant to shine. To resolve this, please replace the following line: ```php $db = Factory::getContainer()->get(DatabaseInterface::class); ``` with: ```php $db = Joomla___39403062_84fb_46e0_bac4_0023f766e827___Power::getContainer()->get(Joomla___7bd29d76_73c9_4c07_a5da_4f7a32aff78f___Power::class); ``` During compilation, this will automatically inject the correct Class into your `use` statements with the proper namespace. The underlying issue is that the preconfigured code provided in the custom code field is technically correct, but references to Joomla core classes are not being converted to their corresponding JPKs. As a result, the Power system is not loaded correctly. We will be updating this default code to address this. In the meantime, simply adding the correct JPK keys, as shown above, will ensure that the required Joomla classes are loaded properly. For more details on how JPKs work in JCB, please refer to the [Joomla Powers Repository](https://github.com/joomengine/joomla-powers/blob/master/README.md).
Owner

Another simple way to resolve this issue is to open Field Types in JCB, select the Custom field-type, and click Reset.

This action restores the field-type to the global version maintained by us, ensuring that the correct JPKs are included in the pre-generated custom code.

The issue has been fixed on our side and verified on Joomla 6, where everything works as expected. For this reason, the issue is now considered resolved and will be closed.

Another simple way to resolve this issue is to open Field Types in JCB, select the Custom field-type, and click Reset. This action restores the field-type to the global version maintained by us, ensuring that the correct JPKs are included in the pre-generated custom code. The issue has been fixed on our side and verified on Joomla 6, where everything works as expected. For this reason, the issue is now considered resolved and will be closed.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1285