Maslosoft Framework Documentation
Flexible Application Foundation
Settings Tabs
This is a helper base class to create tabbed sub-settings. This will create
tabs out of array of provided widgets. It is meant to be used with
application settings infrastructure. This will add tab with @Label
label.
Implementation
First requirement is label. The @Label
must be placed on
class extending from SettingsTabs
.
SettingsTabs
require only one method getWidgets()
, which
should return array of widgets of type WidgetInterface
.
Each widget should implement ModelAwareInterface
which should return working model.
Each of widget is responsible for assiging model to it's form.
Each of the widget must also have @Label
annotation, which
will be used as a tab title.
Example:
In this example, there is no live demo
/** * @Label('Content') */ class SettingsWidget extends SettingsTabs { public function getWidgets() { return [ new ImageSettings, new BrandSettings, new ThemeSettings ]; } }
Each of widget returned by getWidgets()
is self-contained
model editing entity.
Example sub-widget
/** * @Label('Images') */ class ImageSettings extends MsWidget implements AnnotatedInterface, ModelAwareInterface, WidgetInterface { use ModelAware; public function init() { $this->setModel(new ImageSettingsModel()); } public function run() { $model = $this->getModel(); $model->load(); $html = []; $html[] = (string) $form = new ActiveForm([ 'model' => $model ]); $html[] = $form->renderFields(); $html[] = $form->close(); return implode("\n", $html); } }
The Outcome of Implementation
Example image of result of implementing SettingsTabs
like in example above: