Hi,
We are currently developing several modules for our client base which will help us scale production of sites with Processwire. All is going well so far with great information around. But now we came across an issue, which we are stuck with.
One modules installs several fields (successfully), which we want to organize into Fieldset Tabs. And that's where we're currently stuck. Despite trying our own methods and searching in existing modules for references.
Here the field creation code during the module install:
public static $fieldsArray = array(
'strasse' => array('name'=>'WebKitEinstellungenStrasse', 'type'=>'FieldtypeText', 'label'=>'Strasse', 'columnwidth'=>50,'collapsed'=>0),
'plz' => array('name'=>'WebKitEinstellungenPLZ', 'type'=>'FieldtypeText', 'label'=>'Postleitzahl', 'columnwidth'=>15,'collapsed'=>0),
'ort' => array('name'=>'WebKitEinstellungenOrt', 'type'=>'FieldtypeText', 'label'=>'Ort', 'columnwidth'=>35,'collapsed'=>0),
'tel1' => array('name'=>'WebKitEinstellungenTelefonnummer1', 'type'=>'FieldtypeText', 'label'=>'Telefonnummer', 'columnwidth'=>50,'collapsed'=>0),
'tel2' => array('name'=>'WebKitEinstellungenTelefonnummer2', 'type'=>'FieldtypeText', 'label'=>'Telefonnummer 2', 'columnwidth'=>50,'collapsed'=>0),
'email1' => array('name'=>'WebKitEinstellungenEmail1', 'type'=>'FieldtypeText', 'label'=>'E-Mailadresse', 'columnwidth'=>50,'collapsed'=>0),
'email2' => array('name'=>'WebKitEinstellungenEmail2', 'type'=>'FieldtypeText', 'label'=>'E-Mailadresse 2', 'columnwidth'=>50,'collapsed'=>0),
'garagenid' => array('name'=>'WebKitEinstellungenGaragenId', 'type'=>'FieldtypeText', 'label'=>'a-Commerce Nummer', 'columnwidth'=>50,'collapsed'=>0,'description'=>'Benötigt für Fahrzeugmodule. Nur unter Anweisung löschen oder ändern.'),
'fb' => array('name'=>'WebKitEinstellungenFacebook', 'type'=>'FieldtypeText', 'label'=>'Facebook Page URL', 'columnwidth'=>50,'collapsed'=>0),
'insta' => array('name'=>'WebKitEinstellungenInstagram', 'type'=>'FieldtypeText', 'label'=>'Instagramm URL', 'columnwidth'=>50,'collapsed'=>0),
'yt' => array('name'=>'WebKitEinstellungenYouTube', 'type'=>'FieldtypeText', 'label'=>'YouTube URL', 'columnwidth'=>50,'collapsed'=>0),
'footertext' => array('name'=>'WebKitEinstellungenFooterText', 'type'=>'FieldtypeTextarea', 'label'=>'Footer Text', 'columnwidth'=>50,'collapsed'=>0),
'bildertabopen' => array('name'=>'WebKitEinstellungenBilderTabOpen', 'type'=>'FieldtypeFieldsetTabOpen', 'label'=>'Standardbilder','collapsed'=>0,'modal'=>''),
'bilderheader' => array('name'=>'WebKitEinstellungenStandardbilderHeader', 'type'=>'FieldtypeImage', 'label'=>'Standardbild Page Header', 'columnwidth'=>50,'collapsed'=>0,'description'=>'Verwendet, falls bei einer Seite kein spezifisches Kopfbild definiert wird.','entityencodedesc'=>1,'extensions'=>'gif jpg jpeg png','adminThumbs'=>1),
'bildernews' => array('name'=>'WebKitEinstellungenStandardbilderNews', 'type'=>'FieldtypeImage', 'label'=>'Standardbild Neuigkeit', 'columnwidth'=>50,'collapsed'=>0,'description'=>'Verwendet, falls bei einem Newseintrag kein spezifisches Kopfbild definiert wird.','entityencodedesc'=>1,'extensions'=>'gif jpg jpeg png','adminThumbs'=>1),
'bilderfzg' => array('name'=>'WebKitEinstellungenStandardbilderFahrzeuge', 'type'=>'FieldtypeImage', 'label'=>'Standardbild Fahrzeug', 'columnwidth'=>50,'collapsed'=>0,'description'=>'Verwendet, falls ein Fahrzeug kein Bild hat.','entityencodedesc'=>1,'extensions'=>'gif jpg jpeg png','adminThumbs'=>1),
'bildertabclose' => array('name'=>'WebKitEinstellungenBilderTabClose', 'type'=>'FieldtypeFieldsetClose', 'label'=>'Standardbilder Tab Geschlossen','collapsed'=>0,'modal'=>''),
'googlega' => array('name'=>'WebKitEinstellungenGoogleGA', 'type'=>'FieldtypeText', 'label'=>'Google Analytics Konto', 'columnwidth'=>50,'collapsed'=>0,'description'=>'Beispiel: UA-123456-78'),
'googlemaps' => array('name'=>'WebKitEinstellungenGoogleMaps', 'type'=>'FieldtypeTextarea', 'label'=>'Google Maps Code', 'columnwidth'=>50,'collapsed'=>0),
);
private function installFields($templateId){
// Get Fieldgroup
$t = $this->wire('templates')->get($templateId);
$fg = $this->wire('fieldgroups')->get($t->fieldgroup);
// Felder hinzufügen
foreach(static::$fieldsArray as $feld) {
if(!$this->fields->get($feld['name'])){
$f = new Field();
$f->type = $this->modules->get($feld['type']);
$f->name = $feld['name'];
$f->label = $feld['label'];
if (isset($feld['columnwidth'])) $f->columnwidth = $feld['columnwidth'];
$f->collapsed = $feld['collapsed'];
if (isset($feld['description'])) $f->description = $feld['description'];
if (isset($feld['extensions'])) $f->extensions = $feld['extensions'];
if (isset($feld['adminThumbs'])) $f->adminThumbs = $feld['adminThumbs'];
if (isset($feld['modal'])) $f->modal = $feld['modal'];
$f->save(); //
// Feld zur Feldgruppe hinzufügen
$fg->add($f);
}
}
// Feldgruppe speichern
$fg->save();
return $fg;
This adds the tab 'WebKitEinstellungenBilderTabOpen' which is also visible in the template and page. The fields within the open and close tab fields are missing in the basic tab and nothing happens on click on WebKitEinstellungenBilderTabOpen.
Using the Field Exporter we realized that the openFieldID, closeFieldID values were missing. So, after not finding direct references, we did some, uhm, creative workaround by looping through a field tab definition array
public static $tabsArray = array(
'bildertabopen' => array('name'=>'WebKitEinstellungenBilderTabOpen', 'type'=>'FieldtypeFieldsetTabOpen','tabref'=>'WebKitEinstellungenBilderTabClose'),
'bildertabclose' => array('name'=>'WebKitEinstellungenBilderTabClose','type'=>'FieldtypeFieldsetClose','tabref'=>'WebKitEinstellungenBilderTabOpen'),
);
// Tabgruppen zuweisen
foreach(static::$tabsArray as $feld) {
// Feld in Processwire beziehen
if($tab = $this->fields->get($feld['name'])){
// Referenz Tab laden
if($tabref = $this->fields->get($feld['tabref'])){
// Referenz schreiben
if($feld['type'] == 'FieldtypeFieldsetTabOpen') {
$tab->closeFieldID = $tabref->id;
$tab->save();
} else {
$tab->openFieldID = $tabref->id;
$tab->save();
}
}
}
}
This works as far as the setting of the openFieldID, closeFieldId is concerned:
{
"WebKitEinstellungenBilderTabOpen": {
"id": 521,
"type": "FieldtypeFieldsetTabOpen",
"flags": 0,
"name": "WebKitEinstellungenBilderTabOpen",
"label": "Standardbilder",
"closeFieldID": 525,
"modal": "",
"collapsed": 0
}
}
{
"WebKitEinstellungenBilderTabClose": {
"id": 525,
"type": "FieldtypeFieldsetClose",
"flags": 0,
"name": "WebKitEinstellungenBilderTabClose",
"label": "Standardbilder Tab Geschlossen",
"openFieldID": 521
}
}
But in the Admin, the field are still not grouped into the tab.
Now we're stuck and hope someone can help us.
Here some screenshots: