public function SettingsForm::submitForm in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Form/SettingsForm.php \Drupal\cms_content_sync\Form\SettingsForm::submitForm()
- 2.0.x src/Form/SettingsForm.php \Drupal\cms_content_sync\Form\SettingsForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ SettingsForm.php, line 178
Class
- SettingsForm
- Content Sync general settings form.
Namespace
Drupal\cms_content_sync\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$settings = ContentSyncSettings::getInstance();
$settings
->setSiteBaseUrl($form_state
->getValue('cms_content_sync_base_url'));
$settings
->setAuthenticationType($form_state
->getValue('cms_content_sync_authentication_type'));
$settings
->setPreviewEnabled(boolval($form_state
->getValue('cms_content_sync_enable_preview')));
$embed_entities_value = $form_state
->getValue('cms_content_sync_embed_entities');
$embed_entities = [];
foreach ($embed_entities_value as $type => $enable) {
if ($enable) {
$embed_entities[] = $type;
}
}
$settings
->setEmbedEntities($embed_entities);
if (_cms_content_sync_is_cloud_version()) {
$settings
->setDirectSyncCoreAccessEnabled(boolval($form_state
->getValue('cms_content_sync_enable_direct_sync_core_access')));
}
// Set pull dashboard access permissions.
$pull_dashboard_access = $form_state
->getValue('access');
foreach ($pull_dashboard_access as $role => $access) {
// Load role.
$role_obj = Role::load($role);
if ($role === $access) {
$role_obj
->grantPermission('access cms content sync content overview');
$role_obj
->grantPermission('restful get cms_content_sync_import_entity');
$role_obj
->grantPermission('restful post cms_content_sync_import_entity');
$role_obj
->save();
}
else {
$role_obj
->revokePermission('access cms content sync content overview');
$role_obj
->revokePermission('restful get cms_content_sync_import_entity');
$role_obj
->revokePermission('restful post cms_content_sync_import_entity');
$role_obj
->save();
}
}
}