public function FlowForm::save in CMS Content Sync 2.1.x
Same name and namespace in other branches
- 8 src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::save()
- 2.0.x src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ FlowForm.php, line 612
Class
- FlowForm
- Form handler for the Flow add and edit forms.
Namespace
Drupal\cms_content_sync\FormCode
public function save(array $form, FormStateInterface $form_state) {
$config = $this->entity;
$config->{'per_bundle_settings'} = $this
->getCurrentValues($form_state)['per_bundle_settings'];
$per_bundle_settings =& $config->{'per_bundle_settings'};
$export_menu_items_automatically = false;
if (isset($per_bundle_settings['menu_link_content']['menu_link_content']) && PushIntent::PUSH_AUTOMATICALLY == $per_bundle_settings['menu_link_content']['menu_link_content']['settings']['export']) {
$export_menu_items_automatically = true;
}
foreach ($per_bundle_settings as $entity_type_name => &$bundles) {
foreach ($bundles as $bundle_name => &$bundle_config) {
$settings =& $bundle_config['settings'];
$settings['version'] = Flow::getEntityTypeVersion($entity_type_name, $bundle_name);
// If the Flow should pull manually, the Pool selection must also be set to Manual. Otherwise the entities won't
// show up in the pull dashboard. To protect people from that scenario, we're changing that automatically.
if (PullIntent::PULL_MANUALLY === $settings['import']) {
foreach ($settings['import_pools'] as $pool => $setting) {
if (Pool::POOL_USAGE_FORCE === $setting) {
$settings['import_pools'][$pool] = Pool::POOL_USAGE_ALLOW;
}
}
}
// If menu items should be exported automatically, the entity type option "export menu items"
// have to be disabled to avoid a race condition.
if (PushIntent::PUSH_DISABLED != $settings['export']) {
if ($export_menu_items_automatically && isset($settings['handler_settings']['export_menu_items'])) {
$settings['handler_settings']['export_menu_items'] = 0;
}
}
}
}
$config->type = $this
->getCurrentFormType();
$config->variant = Flow::VARIANT_PER_BUNDLE;
$status = $config
->save();
if ($status) {
$this->messenger
->addMessage($this
->t('Saved the %label Flow.', [
'%label' => $config
->label(),
]));
}
else {
$this->messenger
->addMessage($this
->t('The %label Flow could not be saved.', [
'%label' => $config
->label(),
]));
}
$triggering_element = $form_state
->getTriggeringElement();
if ('submit' == $triggering_element['#parents'][1]) {
// Make sure that the export is executed.
\Drupal::request()->query
->remove('destination');
$form_state
->setRedirect('entity.cms_content_sync_flow.export', [
'cms_content_sync_flow' => $config
->id(),
]);
}
else {
$form_state
->setRedirect('entity.cms_content_sync_flow.collection');
}
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler
->moduleExists('cms_content_sync_developer')) {
$config_factory = $this->configFactory;
$developer_config = $config_factory
->getEditable('cms_content_sync.developer');
$mismatching_versions = $developer_config
->get('version_mismatch');
if (!empty($mismatching_versions)) {
unset($mismatching_versions[$config
->id()]);
$developer_config
->set('version_mismatch', $mismatching_versions)
->save();
}
}
// Invalidate the admin menu cache to ensure the Content Dashboard Menu gets shown or hidden.
$this->cacheTagsInvalidator
->invalidateTags([
'config:system.menu.admin',
]);
}