Commit 2d3c7f16 authored by webchick's avatar webchick

Issue #2303521 by swentel, larowlan | alexpott: Fixed CommentTypeForm allows...

Issue #2303521 by swentel, larowlan | alexpott: Fixed CommentTypeForm allows the entity type to be changed.
parent cdebbfb7
......@@ -88,18 +88,28 @@ public function form(array $form, FormStateInterface $form_state) {
'#title' => t('Description'),
);
$options = array();
foreach ($this->entityManager->getDefinitions() as $entity_type) {
if ($entity_type->isFieldable()) {
$options[$entity_type->id()] = $entity_type->getLabel();
if ($comment_type->isNew()) {
$options = array();
foreach ($this->entityManager->getDefinitions() as $entity_type) {
if ($entity_type->isFieldable()) {
$options[$entity_type->id()] = $entity_type->getLabel();
}
}
$form['target_entity_type_id'] = array(
'#type' => 'select',
'#default_value' => $comment_type->getTargetEntityTypeId(),
'#title' => t('Target entity type'),
'#options' => $options,
'#description' => t('The target entity type can not be changed after the comment type has been created.')
);
}
else {
$form['target_entity_type_id_display'] = array(
'#type' => 'item',
'#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(),
'#title' => t('Target entity type'),
);
}
$form['target_entity_type_id'] = array(
'#type' => 'select',
'#default_value' => $comment_type->getTargetEntityTypeId(),
'#title' => t('Target entity type'),
'#options' => $options,
);
if ($this->moduleHandler->moduleExists('content_translation')) {
$form['language'] = array(
......
......@@ -76,6 +76,17 @@ public function testCommentTypeCreation() {
// Check that the comment type was created in site default language.
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
$this->assertEqual($comment_type->language()->getId(), $default_langcode);
// Edit the comment-type and ensure that we cannot change the entity-type.
$this->drupalGet('admin/structure/comment/manage/foo');
$this->assertNoField('target_entity_type_id', 'Entity type file not present');
$this->assertText(t('Target entity type'));
// Save the form and ensure the entity-type value is preserved even though
// the field isn't present.
$this->drupalPostForm(NULL, array(), t('Save'));
\Drupal::entityManager()->getStorage('comment_type')->resetCache(array('foo'));
$comment_type = CommentType::load('foo');
$this->assertEqual($comment_type->getTargetEntityTypeId(), 'node');
}
/**
......
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