-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SLB-328-two-steps-node-creation' into dev
- Loading branch information
Showing
24 changed files
with
545 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
apps/cms/config/sync/core.entity_form_display.node.page.split.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
uuid: a39d0011-2ebf-4b18-a9f0-8b5aeff5b9aa | ||
langcode: en | ||
status: true | ||
dependencies: | ||
config: | ||
- core.entity_form_mode.node.split | ||
- field.field.node.page.body | ||
- field.field.node.page.field_metatags | ||
- node.type.page | ||
- workflows.workflow.basic | ||
module: | ||
- content_moderation | ||
- metatag | ||
- path | ||
id: node.page.split | ||
targetEntityType: node | ||
bundle: page | ||
mode: split | ||
content: | ||
created: | ||
type: datetime_timestamp | ||
weight: 3 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
field_metatags: | ||
type: metatag_firehose | ||
weight: 11 | ||
region: content | ||
settings: | ||
sidebar: true | ||
use_details: true | ||
third_party_settings: { } | ||
langcode: | ||
type: language_select | ||
weight: 1 | ||
region: content | ||
settings: | ||
include_locked: true | ||
third_party_settings: { } | ||
moderation_state: | ||
type: moderation_state_default | ||
weight: 9 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
path: | ||
type: path | ||
weight: 7 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
promote: | ||
type: boolean_checkbox | ||
weight: 5 | ||
region: content | ||
settings: | ||
display_label: true | ||
third_party_settings: { } | ||
status: | ||
type: boolean_checkbox | ||
weight: 10 | ||
region: content | ||
settings: | ||
display_label: true | ||
third_party_settings: { } | ||
sticky: | ||
type: boolean_checkbox | ||
weight: 6 | ||
region: content | ||
settings: | ||
display_label: true | ||
third_party_settings: { } | ||
title: | ||
type: string_textfield | ||
weight: 0 | ||
region: content | ||
settings: | ||
size: 60 | ||
placeholder: '' | ||
third_party_settings: { } | ||
translation: | ||
weight: 4 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
uid: | ||
type: entity_reference_autocomplete | ||
weight: 2 | ||
region: content | ||
settings: | ||
match_operator: CONTAINS | ||
match_limit: 10 | ||
size: 60 | ||
placeholder: '' | ||
third_party_settings: { } | ||
url_redirects: | ||
weight: 8 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
hidden: | ||
body: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
uuid: 5f26940d-fd06-41e0-8e59-9dfcdc9c86df | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- node | ||
id: node.split | ||
label: Split | ||
description: '' | ||
targetEntityType: node | ||
cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Entity Create Split | ||
|
||
A Drupal module which exposes routes to split an entity create form into two parts: | ||
- on the first step, only the required fields are presented. After submitting the form, a entity is already created | ||
- the second step is actually just the entity edit form, containing all the other optional form fields. | ||
|
||
To enable this feature, you must create a form mode with the machine name "split" and enable it on the bundle for which you want to have this feature. | ||
|
||
## Special case for the Gutenberg editor | ||
|
||
The Gutenberg editor does a lot of alterations on the create form. For this reason, it is better that the form alter hook of the gutenberg module to not run at all. This is not easy possible, so right now the easiest approach is to just patch the module with the patch from https://www.drupal.org/project/gutenberg/issues/3445677/ | ||
|
||
The functionality should also work without the patch, but the initial form will not look that nice. |
5 changes: 5 additions & 0 deletions
5
packages/drupal/entity_create_split/entity_create_split.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: Entity Create Split | ||
type: module | ||
description: 'Provides a route for splitting the entity creation in two steps: first for the mandatory fields and a second one, which is actually the edit form, for the rest of the fields.' | ||
package: Custom | ||
core_version_requirement: ^9 || ^10 |
31 changes: 31 additions & 0 deletions
31
packages/drupal/entity_create_split/entity_create_split.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Provides a route for splitting the entity creation in two steps: first for | ||
* the mandatory fields and a second one, which is actually the edit form, for | ||
* the rest of the fields. | ||
*/ | ||
|
||
use Drupal\Core\Entity\ContentEntityType; | ||
use Drupal\Core\Entity\EntityInterface; | ||
|
||
/** | ||
* Implements hook_entity_type_build(). | ||
*/ | ||
function entity_create_split_entity_type_build(array &$entity_types) { | ||
foreach ($entity_types as $entity_type) { | ||
if ($entity_type instanceof ContentEntityType) { | ||
$entity_type->setFormClass('split', $entity_type->getFormClass('default')); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_gutenberg_enabled(). | ||
*/ | ||
function entity_create_split_gutenberg_enabled(EntityInterface $entity) { | ||
if (isset($entity->disableGutenberg) && $entity->disableGutenberg === TRUE) { | ||
return FALSE; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/drupal/entity_create_split/entity_create_split.routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
entity_create_split.create: | ||
path: '/entity/create/{entity_type}/{bundle}' | ||
defaults: | ||
_controller: '\Drupal\entity_create_split\Controller\EntityCreateSplitController::createForm' | ||
_title_callback: '\Drupal\entity_create_split\Controller\EntityCreateSplitController::getTitle' | ||
requirements: | ||
_custom_access: '\Drupal\entity_create_split\Controller\EntityCreateSplitController::access' | ||
options: | ||
_admin_route: TRUE |
9 changes: 9 additions & 0 deletions
9
packages/drupal/entity_create_split/entity_create_split.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
services: | ||
entity_create_split.route_subscriber: | ||
class: Drupal\entity_create_split\EventSubscriber\EntityCreateSplitRequestSubscriber | ||
arguments: | ||
- "@current_route_match" | ||
- "@entity_type.manager" | ||
- "@entity_display.repository" | ||
tags: | ||
- { name: event_subscriber } |
61 changes: 61 additions & 0 deletions
61
packages/drupal/entity_create_split/src/Controller/EntityCreateSplitController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Drupal\entity_create_split\Controller; | ||
|
||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Controller\ControllerBase; | ||
|
||
class EntityCreateSplitController extends ControllerBase { | ||
|
||
/** | ||
* Route callback to show the first part of the entity create form, which | ||
* contains the required fields. | ||
* | ||
* @param string $entity_type | ||
* @param string $bundle | ||
* | ||
* @return array | ||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException | ||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException | ||
*/ | ||
public function createForm($entity_type, $bundle) { | ||
$entityTypeDefinition = $this->entityTypeManager()->getDefinition($entity_type); | ||
$bundleKey = $entityTypeDefinition->getKey('bundle'); | ||
$entity = $this->entityTypeManager()->getStorage($entity_type)->create([$bundleKey => $bundle]); | ||
$entity->disableGutenberg = TRUE; | ||
$editForm = $this->entityTypeManager()->getFormObject($entity_type, 'split')->setEntity($entity); | ||
return \Drupal::formBuilder()->getForm($editForm); | ||
} | ||
|
||
/** | ||
* Title callback for the createForm() route. | ||
*/ | ||
public function getTitle($entity_type, $bundle) { | ||
$entityTypeDefinition = $this->entityTypeManager()->getDefinition($entity_type); | ||
$bundleEntityType = $entityTypeDefinition->getBundleEntityType(); | ||
$bundleLabel = $this->entityTypeManager()->getStorage($bundleEntityType)->load($bundle)->label(); | ||
return $this->t("Create %entity_type: %entity_bundle", [ | ||
'%entity_type' => $entityTypeDefinition->getLabel(), | ||
'%entity_bundle' => $bundleLabel, | ||
]); | ||
} | ||
|
||
/** | ||
* Access callback for the createForm() route. | ||
*/ | ||
public function access($entity_type, $bundle) { | ||
if (!$this->entityTypeManager()->hasDefinition($entity_type)) { | ||
return AccessResult::forbidden(); | ||
} | ||
$entityTypeDefinition = $this->entityTypeManager()->getDefinition($entity_type); | ||
$bundleEntityType = $entityTypeDefinition->getBundleEntityType(); | ||
$bundleEntity = $this->entityTypeManager()->getStorage($bundleEntityType)->load($bundle); | ||
if (!$bundleEntity) { | ||
return AccessResult::forbidden(); | ||
} | ||
|
||
return $this->entityTypeManager() | ||
->getAccessControlHandler($entity_type) | ||
->createAccess($bundle, NULL, [], TRUE); | ||
} | ||
} |
Oops, something went wrong.