Backend\Modules\Groups\Actions\Add::insertWidgets PHP Method

insertWidgets() private method

Insert the widgets
private insertWidgets ( SpoonFormElement[] $widgetPresets ) : mixed
$widgetPresets SpoonFormElement[] The widgets presets.
return mixed
    private function insertWidgets($widgetPresets)
    {
        // empty dashboard sequence
        $this->hiddenOnDashboard = array();
        // loop through all widgets
        foreach ($this->widgetInstances as $widget) {
            if (!BackendModel::isModuleInstalled($widget['module'])) {
                continue;
            }
            foreach ($widgetPresets as $preset) {
                if ($preset->getAttribute('id') !== 'widgets' . $widget['module'] . $widget['widget']) {
                    continue;
                }
                if (!$preset->getChecked()) {
                    if (!isset($this->hiddenOnDashboard[$widget['module']])) {
                        $this->hiddenOnDashboard[$widget['module']] = array();
                    }
                    $this->hiddenOnDashboard[$widget['module']][] = $widget['widget'];
                }
            }
        }
        // build group
        $userGroup['name'] = $this->frm->getField('name')->getValue();
        // build setting
        $setting['name'] = 'hidden_on_dashboard';
        $setting['value'] = serialize($this->hiddenOnDashboard);
        // insert group
        $userGroup['id'] = BackendGroupsModel::insert($userGroup, $setting);
        return $userGroup;
    }