Skip to content
Snippets Groups Projects
Commit fa02529c authored by Alexandre Mallet's avatar Alexandre Mallet Committed by Alexandre Mallet
Browse files

Issue #2927946 by woprrr, alvarito75: The database connection is not...

Issue #2927946 by woprrr, alvarito75: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection
parent b1487b97
No related branches found
No related tags found
No related merge requests found
......@@ -74,7 +74,7 @@ function form_mode_manager_theme() {
*/
function template_preprocess_form_mode_manager_add_list(array &$variables) {
$variables['types'] = [];
$entity_type_id = $variables['entity_type']->id();
$entity_type_id = $variables['entity_type'];
/** @var \Drupal\form_mode_manager\EntityRoutingMapBase $entity_operation_mapping */
$entity_operation_mapping = \Drupal::service("plugin.manager.entity_routing_map")
->createInstance($entity_type_id, ['entityTypeId' => $entity_type_id]);
......@@ -91,4 +91,4 @@ function template_preprocess_form_mode_manager_add_list(array &$variables) {
];
}
}
}
}
\ No newline at end of file
......@@ -130,37 +130,32 @@ abstract class EntityFormModeBase implements ContainerInjectionInterface {
$container->get('form_builder')
);
}
/**
* Displays add content links for available entity types.
*
* Redirects to entity/add/[bundle] if only one content type is available.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition. Useful when a single class is,
* used for multiple, possibly dynamic entity types.
* @param string $form_mode_name
* The operation name identifying the form variation (form_mode).
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* A render array for a list of the entity types that can be added; however,
* if there is only one entity type defined for the site, the function
* will return a RedirectResponse to the entity add page for that one entity
* type.
*/
public function addPage(EntityTypeInterface $entity_type, $form_mode_name) {
$entity_type_name = $entity_type->getBundleEntityType();
$entity_type_id = $entity_type->id();
public function addPage(RouteMatchInterface $route_match) {
$entity_type_id = $route_match->getRouteObject()->getOption('_form_mode_manager_entity_type_id');
$entity_bundle_name = $route_match->getRouteObject()->getOption('_form_mode_manager_bundle_entity_type_id');
$form_mode_name = $route_match->getRouteObject()->getDefault('form_mode_name');
$entity_type_cache_tags = $this->entityTypeManager
->getDefinition($entity_type_name)
->getDefinition($entity_bundle_name)
->getListCacheTags();
$entity_type_definitions = $this->entityTypeManager
->getStorage($entity_type_name)
->getStorage($entity_bundle_name)
->loadMultiple();
$build = [
'#theme' => 'form_mode_manager_add_list',
'#entity_type' => $entity_type,
'#entity_type' => $entity_type_id,
'#cache' => [
'tags' => Cache::mergeTags($entity_type_cache_tags, $this->formModeManager->getListCacheTags()),
],
......@@ -184,7 +179,7 @@ abstract class EntityFormModeBase implements ContainerInjectionInterface {
$bundle = array_shift($content);
$entity_routes_infos = $this->entityRoutingMap->createInstance($entity_type_id, ['entityTypeId' => $entity_type_id])->getPluginDefinition();
return $this->redirect($entity_routes_infos['operations']['add_form'] . ".$form_mode_name", [
$entity_type_name => $bundle->id(),
$entity_bundle_name => $bundle->id(),
]);
}
......
......@@ -166,6 +166,8 @@ class FormModesSubscriber extends RouteSubscriberBase {
public function getFormModeListPageRoute(EntityTypeInterface $entity_type, array $form_mode) {
$route = NULL;
$entity_type_id = $entity_type->id();
$entity_type_bundle_id = $entity_type->getBundleEntityType();
$bundle_entity_type_id = !empty($entity_type_bundle_id) ? $entity_type_bundle_id : $entity_type_id;
$has_active_mode = $this->formModeManager->hasActiveFormMode(
$entity_type_id,
$this->formModeManager->getFormModeMachineName($form_mode['id'])
......@@ -178,13 +180,14 @@ class FormModesSubscriber extends RouteSubscriberBase {
'_controller' => static::FORM_MODE_DEFAULT_CONTROLLER . '::addPage',
'_title' => $this->t('Add @entity_type', ['@entity_type' => $entity_type->getLabel()])
->render(),
'entity_type' => $entity_type,
'form_mode_name' => $this->formModeManager->getFormModeMachineName($form_mode['id']),
])
->addRequirements([
'_permission' => "use {$form_mode['id']} form mode",
])
->setOptions([
'_form_mode_manager_entity_type_id' => $entity_type_id,
'_form_mode_manager_bundle_entity_type_id' => $bundle_entity_type_id,
'_admin_route' => TRUE,
]);
$this->userListEnhancements($route, $entity_type->id());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment