Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -41,7 +40,7 @@ class ExtensionField extends ListField
*/
public function getOptions()
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('DISTINCT ' . $db->quoteName('extension'))
->from($db->quoteName('#__action_logs'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;

/**
Expand Down Expand Up @@ -53,7 +52,7 @@ protected function getOptions()
{
static::$options[$hash] = parent::getOptions();

$db = Factory::getDbo();
$db = $this->getDatabase();

// Construct the query
$query = $db->getQuery(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
\defined('_JEXEC') or die;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -42,7 +41,7 @@ class LogtypeField extends ListField
*/
public function getOptions()
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('extension'))
->from($db->quoteName('#__action_logs_extensions'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -41,7 +40,7 @@ class PlugininfoField extends FormField
*/
protected function getInput()
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
->from($db->quoteName('#__extensions'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function getOptions()
? (int) reset($oldCat)
: (int) $oldCat;

$db = Factory::getDbo();
$db = $this->getDatabase();
$user = Factory::getUser();

$query = $db->getQuery(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ComponentsCategoryField extends ListField
protected function getOptions()
{
// Initialise variable.
$db = Factory::getDbo();
$db = $this->getDatabase();
$options = array();

$query = $db->getQuery(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function getInput()

if ($value)
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__categories'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConfigComponentsField extends ListField
*/
protected function getOptions()
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('name AS text, element AS value')
->from('#__extensions')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected function getInput()
protected function getUserGroups()
{
// Get a database object.
$db = Factory::getDbo();
$db = $this->getDatabase();

// Get the user groups from the database.
$query = $db->getQuery(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function getInput()

if ($value)
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('name'))
->from($db->quoteName('#__contact_details'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function getInput()

if ($value)
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__content'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComponentsFieldgroupField extends ListField
protected function getOptions()
{
// Initialise variable.
$db = Factory::getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select('DISTINCT a.name AS text, a.element AS value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComponentsFieldsField extends ListField
protected function getOptions()
{
// Initialise variable.
$db = Factory::getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select('DISTINCT a.name AS text, a.element AS value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Form\FormField;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected function getInput()
if ($extension)
{
// Get the database object and a new query object.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);

// Build the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Joomla\CMS\Form\Field\ListField;
use Joomla\Utilities\ArrayHelper;


/**
* Fields Groups
*
Expand Down Expand Up @@ -44,7 +43,7 @@ protected function getOptions()
$user = Factory::getUser();
$viewlevels = ArrayHelper::toInteger($user->getAuthorisedViewLevels());

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select(
[
Expand Down
20 changes: 19 additions & 1 deletion administrator/components/com_fields/src/Model/FieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\Exception\DatabaseNotFoundException;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand Down Expand Up @@ -301,7 +304,9 @@ private function checkDefaultValue($data)
$node = $dom->appendChild(new \DOMElement('form'));

// Trigger the event to create the field dom node
Factory::getApplication()->triggerEvent('onCustomFieldsPrepareDom', array($obj, $node, new Form($data['context'])));
$form = new Form($data['context']);
$form->setDatabase($this->getDatabase());
Factory::getApplication()->triggerEvent('onCustomFieldsPrepareDom', array($obj, $node, $form));

// Check if a node is created
if (!$node->firstChild)
Expand All @@ -321,6 +326,19 @@ private function checkDefaultValue($data)
return true;
}

if ($rule instanceof DatabaseAwareInterface)
{
try
{
$rule->setDatabase($this->getDatabase());
}
catch (DatabaseNotFoundException $e)
{
@trigger_error(sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED);
$rule->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
}
}

try
{
// Perform the check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getGroups()
$groups = array();

// Get the database object and a new query object.
$db = Factory::getDbo();
$db = $this->getDatabase();

// Levels subquery.
$levelQuery = $db->getQuery(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getOptions()
$lang = Factory::getLanguage();
$options = array();

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('id', 'value'))
->select($db->quoteName('title', 'text'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die();

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -41,7 +40,7 @@ class SearchfilterField extends ListField
public function getOptions()
{
// Build the query.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('f.title AS text, f.filter_id AS value')
->from($db->quoteName('#__finder_filters') . ' AS f')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected function getGroups()
if ($menuType)
{
// If the menutype is empty, group the items by menutype.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__menu_types'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getOptions()
return false;
}

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getOptions()
{
$options = array();

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function getInput()

if ($value)
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__menu'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UserMessagesField extends UserField
protected function getGroups()
{
// Compute usergroups
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('id')
->from('#__usergroups');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function getInput()
if ($value)
{
$id = (int) $value;
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('name'))
->from($db->quoteName('#__newsfeeds'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function getOptions()
{
$options = array();

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\OrderingField;

/**
Expand All @@ -36,7 +35,7 @@ class PluginorderingField extends OrderingField
*/
protected function getQuery()
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$folder = $this->form->getValue('folder');

// Build the query for the ordering list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComponentsWorkflowField extends ListField
protected function getOptions()
{
// Initialise variable.
$db = Factory::getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select('DISTINCT a.name AS text, a.element AS value')
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Form/Field/AliastagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AliastagField extends ListField
protected function getOptions()
{
// Get list of tag type alias
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down
4 changes: 1 addition & 3 deletions libraries/src/Form/Field/AuthorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;

/**
* Form Field to load a list of content authors
*
Expand Down Expand Up @@ -51,7 +49,7 @@ protected function getOptions()
{
static::$options[$hash] = parent::getOptions();

$db = Factory::getDbo();
$db = $this->getDatabase();

// Construct the query
$query = $db->getQuery(true)
Expand Down
Loading