we are evaluating JD-Builder as the main editing system on some of our future sites.
One crucial feature we are looking for is the possibility to add custom field types when editing pages.
An example:
Defining a new element in JD Builder is easy: Just create the directory containing the php-files and the xml-file containing the field definitions.
But some of our data comes for instance from external databases or webservices ecc. for which we usually create a custom field type within Joomla, which create the dropdowns containing the possible options or something like that.
We tried to create a custom field type and add the containing directory to the elements xml:
<fields addfieldpath="/plugins/system/jdbuilder/fields">
But if used in the form xml, for instance like this:
<field type="cities".....
It simply does not show up.
Are we missing something or does JD Builder not support custom field types?
Thanks in advance
Best regards
The administrator has disabled public write access.
I am sure you'll have in place. If you have written something and would like to share with others. Please post the details on this thread. sharing the code via github.
Thank You,
If you like our support and products, tweet us at joomdev and let the world know about it.
The administrator has disabled public write access.
You wrote that you want to fetch data from external databases. I don't know what kind of data this is, but if it's e.g. a small SQL query and you only want to output a text or a number, you can use my solution. Note: This element is intended to output a text or a number (number of entries, for example) as text.
I create two elements of my own a "SQL-Query" for a simple output and a "SQL-Number-Counter" based on the original "Number-Counter" element with a sql query for the start and end number.
You need the following element structure based on the "sql-query" folder:
sql-query.xml
This defines the element structure for the input values (text, typography, color, ....).
Here we have basicly a input field for the query, a setup for the typo and a colorpicker for the fontcolor.
Warning: Spoiler![ Click to expand ][ Click to hide ]
<?xml version="1.0" encoding="utf-8"?>
<element type="sql-query">
<title>SQL Query</title>
<icon></icon>
<creationDate>April 2020</creationDate>
<author>JS</author>
<copyright>Copyright (C) 2020 Joomdev, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0</version>
<form>
<fields>
<fieldset name="general" label="JDB_GENERAL_TITLE">
<field type="group" name="basic" label="JDB_BASIC_TITLE"></field>
<!-- Element Options -->
<field
name="sqlQuery"
type="text"
label="SQL_QUERY_LBL"
default=""
group="basic"
>
</field>
<field name="sqlQueryTypography" type="typography" label="SQL_QUERY_TYPOGRAPHY" group="basic" default="" responsive="true">
</field>
<field type="color" name="sqlQueryFontColor" label="SQL_QUERY_COLOR" default="" group="basic">
</field>
</fieldset>
</fields>
</form>
</element>
tmpl/default.js
The javascript file render the element in the backends page builder.
Warning: Spoiler![ Click to expand ][ Click to hide ]
(function () {
var JDBuilderElementSqlQuery = function (element) {
var sqlQueryContent = element.params.get("sqlQuery", "");
if (sqlQueryContent == '') {
return;
}
var sqlQueryStyle = JDBRenderer.ElementStyle('> .sqlQuery');
element.addChildrenStyle([sqlQueryStyle]);
// content typography
var typography = element.params.get("sqlQueryTypography", null);
if (typography !== null) {
JDBRenderer.DEVICES.forEach(function (_deviceObj) {
if (_deviceObj.key in typography) {
sqlQueryStyle.addStyle(JDBRenderer.Helper.typographyValue(typography[_deviceObj.key]), _deviceObj.type);
}
});
}
sqlQueryStyle.addCss('color', element.params.get("sqlQueryFontColor", ''));
var sqlQueryHTML = [];
// Content
sqlQueryHTML.push('<div class="sqlQuery">' + sqlQueryContent + '</div>');
return sqlQueryHTML.join('');
}
window.JDBuilderElementSqlQuery = JDBuilderElementSqlQuery;
})();
tmpl/default.php
The default.php is responsible for the output in the frontend.
Warning: Spoiler![ Click to expand ][ Click to hide ]
<?php
/**
* @package JD Builder
* @author JS
* @copyright April 2020
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
extract($displayData);
// Params
$sqlQuery = $element->params->get("sqlQuery", "");
if (empty($sqlQuery)) {
return;
}
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query= $sqlQuery;
$db->setQuery($query);
$result = $db->loadResult();
// Display
echo '<div class="sqlQuery">' .$result. '</div>';
$contentStyle = new JDPageBuilder\Element\ElementStyle('> .sqlQuery');
$contentStyle->addCss("color", $element->params->get("sqlQueryFontColor", ""));
$element->addChildStyle($contentStyle);
$typography = $element->params->get('sqlQueryTypography', null);
if (!empty($typography)) {
foreach (JDPageBuilder\Helper::$devices as $deviceKey => $device) {
if (isset($typography->{$deviceKey}) && !empty($typography->{$deviceKey})) {
$contentStyle->addStyle(JDPageBuilder\Helper::typographyValue($typography->{$deviceKey}), $device);
}
}
}
?>
en-GB.sql-query.ini
Here you can define the language labels for the xml file.
Warning: Spoiler![ Click to expand ][ Click to hide ]
All you need is to copy the folder to JOOMLAROOT/plugins/system/jdbuilder/elements/.
If you want to add an icon for the backend, you need to upload suitable svg image to media/jdbuilder/images/icons/elements/ and link that into the xml file inside the <icon> brackets.
But there is a issue. It is not possible to render the sql query on the page builder at the backend.
Thats because the output is generatet by javascript and js can not handle php sql queries.
I guess it is possible to outsource the sql query in an external php file and get the query result by ajax and a post method.
Unfortunately, I have no experience with this and I have no idea about the security of the post method itself.
JoomDev is not affiliated with or endorsed by Open Source Matters or the Joomla! Project. The Joomla! logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.