jDiction Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

jDiction 2.2.0 released. http://jdiction.org/downloads

Author Topic: XML format for component  (Read 14369 times)

pagchen

  • Newbie
  • *
  • Posts: 3
    • View Profile
XML format for component
« on: February 06, 2014, 07:52:21 pm »

Hi,
I am building a custom component and wanted to create an xml file so my component is using jdiction powerful translation.
I did find bits in many places, so I thought I would combine all the info I gathered here.

First you need to create a file called jdiction.xml in the administration folder (administrator/components/my_component/jdiction.xml)

The format to use is like this:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<jdiction>
  <component>com_mycomponent</component>
  <sections>
    <section>
      <tables>
        <table>
          <name>#__mycomponent_items</name>
          <key>id</key>
          <class>mycomponentTableItem</class>
          <file>item.php</file>
          <cache fullfetch="1" />
        </table>

      </tables>
      <views>
        <view name="item" list="items" layout="edit" default="true">
          <form import="form.xml">
          <fieldset name="main" label="COM_JDICTION_TRANSLATION_FIELDSET_MAIN">
              <field name="title" />
      <field name="otherfields" />
          </fieldset>
          </form>
        </view>
      </views>
    </section>
<section>
<tables>
<table>
  <name>#__mycomponent_otheritems</name>
  <key>id</key>
  <class>mycomponentTableOtheritem</class>
  <file>otheritem.php</file>
  <cache fullfetch="1" />
</table>
</tables>
<views>
<view name="otheritem" list="otheritems" layout="edit" default="true">
  <form import="form.xml">
  <fieldset name="main" label="COM_JDICTION_TRANSLATION_FIELDSET_MAIN">
  <field name="title" />
  <field name="otherfields" />
</fieldset>
  </form>
</view>
</views>
</section>
  </sections>
</jdiction>

So basically, you need to put each table in its section, change the name of the tables and component. Adjust the view names. Put the primary key of the table in the key field.
I still have to discover what the cache fullfetch is doing.

Cheers,
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: XML format for component
« Reply #1 on: February 09, 2014, 02:19:09 pm »

Hi pagchen,

I should really start to write a documentation (I already did start but stopped because I didn't have the time :-()

thx for your start.
The "fullfetch" option means that all translation for this table getting loaded by the first time a item get requested, this is useful for the #__menu table for example because I know that this table will always be loaded completely because Joomla needs it.

thx
Logged
Joomla! 5.0 Release Manager
Vote at JED

pipedream

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: XML format for component
« Reply #2 on: July 11, 2014, 06:08:54 am »

Hi Harald,

Yes, please complete the documentation.

While using jDiction with Event Booking, I had some problems trying to find the correct values for each tag and parameter.
So, I will try my best to add something to the useful information already posted by pagchen.

A jdiction.xml file should be created inside administrator/components/com_my_component/.

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<jdiction>
  <component>com_my_component</component>
  <sections>
    <section>
      <tables>
        <table>
          <name>#__db_table</name>
          <key>db_table_key</key>
          <class>MyComponentTable</class>
          <file>my_component.php</file>
          <cache fullfetch="0" />
          <exportfilter/>
        </table>
      </tables>
      <views>
        <view name="edit_view" list="list_view" layout="edit_layout" default="true">
          <form import="my_component_form.xml">
            <fieldset name="main" label="COM_JDICTION_TRANSLATION_FIELDSET_MAIN">
              <field name="a_field" />
      <field name="another_field" />
            </fieldset>
            <fields name="extra_fields">
              <fieldset name="extra" label="ANOTHER_TRANSLATION_STRING">
                <field name="an_extra_field" />
              </fieldset>
            </fields>
          </form>
        </view>
      </views>
    </section>
  </sections>
</jdiction>

<tables> tag

Locate the model file, such as administrator/components/com_my_component/tables/my_component.php.
The <table><file> tag should contain the name of this file and in its content we can also find the values for the tags:
  • <table><class>, within the code "class MyComponentTable extends JTable";
  • <table><name>, within the code "parent::__construct('#__db_table', 'db_table_key', $db);";
  • <table><key>, within the code "parent::__construct('#__db_table', 'db_table_key', $db);".
As far I understood, <table><cache> should have the attribute fullfetch equal to 0 unless we are sure that all the table records are always being fetched by Joomla. Don't know if this tag is mandatory.

The tag <table><exportfilter> seems to be optional and allows you to filter records through an SQL query when exporting the table, right?

<views> tag

In you administrator's panel visit the component and get the view/task and layout values of the URL of the listing and editing pages.
The <view> tag should have the following attributes:
  • name, value of the view/task parameter in the editing URL:
    "mysite/administrator/index.php?option=my_component&view=edit_view" or
    "mysite/administrator/index.php?option=my_component&task=edit_view.edit_layout";
  • list, value of the view/task parameter in the listing URL:
    "mysite/administrator/index.php?option=my_component&view=list_view" or
    "mysite/administrator/index.php?option=my_component&task=list_view.list_layout";
  • layout, value of the layout parameter in the editing URL:
    "mysite/administrator/index.php?option=my_component&task=edit_view.edit_layout" or
    "mysite/administrator/index.php?option=my_component&task=edit_view&layout=edit_layout"
    (if the layout parameter is not defined, the value "default" should be used);
  • default, when equal to true it should allow translations on the default component page (without any view/task parameter defined, such as "mysite/administrator/index.php?option=my_component), seems to be useful only when the default task is not the editing or listing because for these it would be enough to specify as "default" its attribute (name or list, respectively).
The attribute import of the tag <view><form> accepts XML files (separated by commas) that define forms created using JForm in the administrator/components/com_my_component/models/forms/ folder. When importing these form definitions, we don't have to specify each attribute of the field tags beyond the name attribute, unless we want to change attribute values or specify additional attributes.

Regarding the fieldset, fields and field tags, these should follow what is described in Joomla! Documentation:
http://docs.joomla.org/XML_JForm_form_definitions

Still, there are some aspects worth mentioning:
  • fieldset tag must have a name attribute and, if a XML form definition file is imported, its value or the value of an additional attribute named reffield should be the same as the one set in the file;
  • field tag can have an alias auto-generated from another field by setting the following attributes and values: type="jdalias" and field="source_field_name" (usually source_field_name is "title");
  • export of a particular field can be disabled if its attribute export is equal to "false";
  • field tag can accept a pair of attributes for holding multiple table columns: the multifield attribute holds the column names (separated by commas) and the seperator attribute defines what separates each column value inside the field; for now, this feature seems to only work with the Joomla content table;
  • fields tag can be used for handling multiple fields stored as a JSON format string in a single table column.


Please review and correct this information, thanks.
Logged