I’m trying to build a form with MODx 0.9.6 documents and TV, here is my shema (fields are the defaults):
<object class="SiteContent" table="site_content" extends="xPDOSimpleObject">
...
<composite alias="SiteTmplvarContentvalues" class="SiteTmplvarContentvalues" key="id" local="id" foreign="contentid" cardinality="many" owner="local" />
</object>
<object class="SiteTmplvarContentvalues" table="site_tmplvar_contentvalues" extends="xPDOSimpleObject">
...
<aggregate alias="SiteTmplvars" class="SiteTmplvars" key="id" local="tmplvarid" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="SiteContent" class="SiteContent" key="id" local="contentid" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="SiteTmplvars" table="site_tmplvars" extends="xPDOSimpleObject">
...
<composite alias="SiteTmplvarContentvalues" class="SiteTmplvarContentvalues" key="id" local="id" foreign="tmplvarid" cardinality="many" owner="foreign" />
In a snippet I’m trying to build the form with makeform, there is a fourth parameter for setFormObject of xPDOObject type which I don’t know how to use, perhaps it’s the problem.
<?php
$form->setFormObject($object, $excludeFields,true); // true to include related element
$elements )
$form->formElements['save']= array (
'type' => 'submit',
'name' => 'save',
'value' => 'Save',
);
echo <<<END
<div class="formError">[+formError+]</div>
<div class="formMessage">[+formMessage+]</div>
<form action="[~[*id*]~]" name="sampleForm" id="sampleForm" method="POST">
[+sampleForm+]
END;
return $form->buildForm();
echo "</form>";
?>
My form is correctly builded but don’t show any TV.
I "hacked" the _setFormObject function in makeform class:
<?php
...
if ($this->includeRelated && !empty ($object->_relatedObjects)) {
echo '<h2 id="pp"> include related and not empty de related object</h2> ';
foreach ($object->_relatedObjects as $relClass => $relDef) {
echo '<h3 id="pppp">'." $relClass $relDef".'</h3> ';
// here $relClass is set to "SiteTmplvarContentvalues" but $relDef is empty <-------------------------
echo print_r($relDef); // Array()1
foreach ($relDef as $relKey => $related) {
echo '<h3 id="u">'."relkey : $reKey related: $related object".'</h3> ';
...
?>
I don’t know why $relDef is empty, must I add something in the class or whatever ?
Thanks in advance.