Commit fd4c6da9 authored by webchick's avatar webchick

Issue #2354469 by swentel, Vj, R. Volk: Can't create node, if preview is required

parent 1fd2961d
......@@ -29,6 +29,11 @@ class NodeForm extends ContentEntityForm {
*/
protected $tempStoreFactory;
/**
* Whether this node has been previewed or not.
*/
protected $hasBeenPreviewed = FALSE;
/**
* Constructs a ContentEntityForm object.
*
......@@ -87,6 +92,8 @@ public function form(array $form, FormStateInterface $form_state) {
$form_state->setRebuild();
$this->entity = $preview->getFormObject()->getEntity();
unset($this->entity->in_preview);
$this->hasBeenPreviewed = TRUE;
}
/** @var \Drupal\node\NodeInterface $node */
......@@ -219,7 +226,7 @@ protected function actions(array $form, FormStateInterface $form_state) {
$node = $this->entity;
$preview_mode = $node->type->entity->getPreviewMode();
$element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!$form_state->getErrors() && $form_state->get('node_preview'));
$element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || $this->hasBeenPreviewed;
// If saving is an option, privileged users get dedicated form submit
// buttons to adjust the publishing status while saving in one go.
......
......@@ -194,6 +194,16 @@ function testPagePreview() {
$this->assertLink($newterm1);
$this->assertLink($newterm2);
$this->assertNoLink($newterm3);
// Check with required preview.
$node_type = NodeType::load('page');
$node_type->setPreviewMode(DRUPAL_REQUIRED);
$node_type->save();
$this->drupalGet('node/add/page');
$this->assertNoRaw('edit-submit');
$this->drupalPostForm('node/add/page', array($title_key => 'Preview'), t('Preview'));
$this->clickLink(t('Back to content editing'));
$this->assertRaw('edit-submit');
}
/**
......
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