for curiosity: I'm using this method to add fields to the standard articles: https://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin/de
I have to use this, since the fields-component does not have subforms, but i prefer this anyway, since i have more control if i write it as plugin.. This has worked great in the last few years, but i have one little issue: When i want to use a custom form field type inside the subform (with the multiple attribute, so that i can create multiple items), i do not know how to set/get the saved value, for instance if i have a select, i have to get the saved value somehow when reopening the article. If it was a single field thats no problem, just get the attributes and get the specific value. But since it is a list, how do i get the current value of that field?
Thanks in advance and best regards
Edit:
The code inside the main form xml:
<fieldset name="newset" label="New Set">
<field
name="person"
type="subform"
formsource="plugins/content/cfields/forms/person.xml"
multiple="true"
min="1"
max="99" />
</fieldset>
The person xml:
<?xml version="1.0" encoding="UTF-8"?>
<form>
<field
type="building"
name="building"
label="Building person works in" />
<field
type="text"
name="name"
label="Name" />
</form>
Field code:
<?php
defined('_JEXEC') or die();
jimport('joomla.form.formfield');
class JFormFieldBuilding extends JFormField
{
protected $type = 'Building';
private function getBuildings()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')->from($db->quoteName('#__buildings'));
$db->setQuery($query);
$result = $db->loadObjectList();
return $result;
}
public function getInput()
{
$rows = $this->getBuildings();
$return = '<select id="'.htmlspecialchars($this->id, ENT_QUOTES).'" name="'.htmlspecialchars($this->name, ENT_QUOTES).'">';
foreach($rows as $row)
{
$return .= '<option value="'.htmlspecialchars($row->alias, ENT_QUOTES).'">';
$return .= htmlspecialchars($row->title, ENT_QUOTES);
$return .= '</option>';
}
$return .= '</select>';
return $return;
}
}
Since this field will be repeated and saved in the attributes column of the current article, how do i find out the current value?