/**
* @route motif-config/{string}
*
* @param string $motifName
*/
public function configure(string $motifName)
{
$motifs = $this->getAllMotifs();
if (!\array_key_exists($motifName, $motifs)) {
\Airship\redirect($this->airship_cabin_prefix . '/motifs');
}
if (!$this->can('update')) {
\Airship\redirect($this->airship_cabin_prefix . '/motifs');
}
$selected = $motifs[$motifName];
$path = ROOT . '/Motifs/' . $selected['supplier'] . '/' . $selected['name'];
// Should we load overload the configuration lens?
if (\file_exists($path . '/lens/config.twig')) {
Gadgets::loadCargo('bridge_motifs_config_overloaded', 'motif/' . $motifName . '/config.twig');
}
$inputFilter = null;
if (\file_exists($path . '/config_filter.php')) {
$inputFilter = $this->getConfigFilter($path . '/config_filter.php');
}
try {
$motifConfig = \Airship\loadJSON(ROOT . '/config/motifs/' . $motifName . '.json');
} catch (\Throwable $ex) {
$motifConfig = [];
}
// Handle POST data
if ($inputFilter instanceof InputFilterContainer) {
$post = $this->post($inputFilter);
} else {
$post = $this->post();
if (\is_string($post['motif_config'])) {
$post['motif_config'] = \Airship\parseJSON($post['motif_config'], true);
}
}
if ($post) {
if (empty($post['motif_config'])) {
$post['motif_config'] = [];
}
if ($this->saveMotifConfig($motifName, $post['motif_config'])) {
\Airship\redirect($this->airship_cabin_prefix . '/motif_config/' . $motifName);
}
}
$this->lens('motif_configure', ['cabin_name' => $motifName, 'motifs' => $motifs, 'motif_config' => $motifConfig, 'title' => \__('Configuring %s/%s', 'default', Util::noHTML($selected['supplier']), Util::noHTML($selected['name']))]);
}