Issue #2303521 by swentel, larowlan | alexpott: Fixed CommentTypeForm allows the entity type to be changed.
parent
cdebbfb7bf
commit
2d3c7f1642
|
@ -88,18 +88,28 @@ class CommentTypeForm extends EntityForm {
|
|||
'#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 @@ class CommentTypeTest extends CommentTestBase {
|
|||
// 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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue