Commit 42c492cd authored by catch's avatar catch

Issue #2892967 by amateescu, Sam152:...

Issue #2892967 by amateescu, Sam152: \Drupal\content_moderation\EntityTypeInfo::formAlter() is half broken
parent d9247c2e
......@@ -51,14 +51,9 @@ public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface
* {@inheritdoc}
*/
public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
/* @var \Drupal\node\Entity\NodeType $entity */
$entity = $form_state->getFormObject()->getEntity();
if ($this->moderationInfo->getWorkflowForEntity($entity)) {
// Force the revision checkbox on.
$form['workflow']['options']['#default_value']['revision'] = 'revision';
$form['workflow']['options']['revision']['#disabled'] = TRUE;
}
// Force the revision checkbox on.
$form['workflow']['options']['#default_value']['revision'] = 'revision';
$form['workflow']['options']['revision']['#disabled'] = TRUE;
}
}
......@@ -288,9 +288,12 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
public function formAlter(array &$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state->getFormObject();
if ($form_object instanceof BundleEntityFormBase) {
$type = $form_object->getEntity()->getEntityType();
if ($this->moderationInfo->canModerateEntitiesOfEntityType($type)) {
$this->entityTypeManager->getHandler($type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
$config_entity_type = $form_object->getEntity()->getEntityType();
$bundle_of = $config_entity_type->getBundleOf();
if ($bundle_of
&& ($bundle_of_entity_type = $this->entityTypeManager->getDefinition($bundle_of))
&& $this->moderationInfo->canModerateEntitiesOfEntityType($bundle_of_entity_type)) {
$this->entityTypeManager->getHandler($config_entity_type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
}
}
elseif ($form_object instanceof ContentEntityFormInterface && in_array($form_object->getOperation(), ['edit', 'default'])) {
......
......@@ -11,6 +11,9 @@ class ModerationStateNodeTypeTest extends ModerationStateTestBase {
/**
* A node type without moderation state disabled.
*
* @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
* @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
*/
public function testNotModerated() {
$this->drupalLogin($this->adminUser);
......@@ -27,6 +30,9 @@ public function testNotModerated() {
/**
* Tests enabling moderation on an existing node-type, with content.
*
* @covers \Drupal\content_moderation\EntityTypeInfo::formAlter
* @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter
*/
public function testEnablingOnExistingContent() {
$editor_permissions = [
......
......@@ -97,6 +97,11 @@ protected function getWorkflowTransitionPermission($workflow_id, $transition_id)
protected function createContentTypeFromUi($content_type_name, $content_type_id, $moderated = FALSE, $workflow_id = 'editorial') {
$this->drupalGet('admin/structure/types');
$this->clickLink('Add content type');
// Check that the 'Create new revision' checkbox is checked and disabled.
$this->assertSession()->checkboxChecked('options[revision]');
$this->assertSession()->fieldDisabled('options[revision]');
$edit = [
'name' => $content_type_name,
'type' => $content_type_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment