summaryrefslogtreecommitdiffstats
path: root/core/modules/node/src/NodeForm.php
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-12-13 15:45:12 (GMT)
committerNathaniel Catchpole2016-12-13 15:45:12 (GMT)
commitf4a242f15463637805c3392c3eedf6f2b714923c (patch)
treedd5c944979d6c298b28ead5f57b8ac5bd5d593a0 /core/modules/node/src/NodeForm.php
parent0f139055718b608edfac1422e89667c7a7bf172a (diff)
Issue #2669802 by chr.fritsch, Berdir, seanB, bojanz, dawehner, yoroy, slashrsm, tstoeckler: Add a content entity form which allows to set revisions
Diffstat (limited to 'core/modules/node/src/NodeForm.php')
-rw-r--r--core/modules/node/src/NodeForm.php83
1 files changed, 2 insertions, 81 deletions
diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php
index 2828030..4193923 100644
--- a/core/modules/node/src/NodeForm.php
+++ b/core/modules/node/src/NodeForm.php
@@ -26,7 +26,7 @@ class NodeForm extends ContentEntityForm {
protected $hasBeenPreviewed = FALSE;
/**
- * Constructs a ContentEntityForm object.
+ * Constructs a NodeForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
@@ -51,19 +51,6 @@ class NodeForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
- protected function prepareEntity() {
- /** @var \Drupal\node\NodeInterface $node */
- $node = $this->entity;
-
- if (!$node->isNew()) {
- // Remove the revision log message from the original node entity.
- $node->revision_log = NULL;
- }
- }
-
- /**
- * {@inheritdoc}
- */
public function form(array $form, FormStateInterface $form_state) {
// Try to restore from temp store, this must be done before calling
// parent::form().
@@ -102,55 +89,15 @@ class NodeForm extends ContentEntityForm {
$form['#title'] = $this->t('<em>Edit @type</em> @title', array('@type' => node_get_type_label($node), '@title' => $node->label()));
}
- $current_user = $this->currentUser();
-
// Changed must be sent to the client, for later overwrite error checking.
$form['changed'] = array(
'#type' => 'hidden',
'#default_value' => $node->getChangedTime(),
);
- $form['advanced'] = array(
- '#type' => 'vertical_tabs',
- '#attributes' => array('class' => array('entity-meta')),
- '#weight' => 99,
- );
$form = parent::form($form, $form_state);
- // Add a revision_log field if the "Create new revision" option is checked,
- // or if the current user has the ability to check that option.
- $form['revision_information'] = array(
- '#type' => 'details',
- '#group' => 'advanced',
- '#title' => t('Revision information'),
- // Open by default when "Create new revision" is checked.
- '#open' => $node->isNewRevision(),
- '#attributes' => array(
- 'class' => array('node-form-revision-information'),
- ),
- '#attached' => array(
- 'library' => array('node/drupal.node'),
- ),
- '#weight' => 20,
- '#optional' => TRUE,
- );
-
- $form['revision'] = array(
- '#type' => 'checkbox',
- '#title' => t('Create new revision'),
- '#default_value' => $node->type->entity->isNewRevision(),
- '#access' => $current_user->hasPermission('administer nodes') && !$node->isNew(),
- '#group' => 'revision_information',
- );
-
- $form['revision_log'] += array(
- '#states' => array(
- 'visible' => array(
- ':input[name="revision"]' => array('checked' => TRUE),
- ),
- ),
- '#group' => 'revision_information',
- );
+ $form['advanced']['#attributes']['class'][] = 'entity-meta';
// Node author information for administrators.
$form['author'] = array(
@@ -304,32 +251,6 @@ class NodeForm extends ContentEntityForm {
}
/**
- * {@inheritdoc}
- *
- * Updates the node object by processing the submitted values.
- *
- * This function can be called by a "Next" button of a wizard to update the
- * form state's entity with the current step's values before proceeding to the
- * next step.
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- // Build the node object from the submitted values.
- parent::submitForm($form, $form_state);
- $node = $this->entity;
-
- // Save as a new revision if requested to do so.
- if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
- $node->setNewRevision();
- // If a new revision is created, save the current user as revision author.
- $node->setRevisionCreationTime(REQUEST_TIME);
- $node->setRevisionUserId(\Drupal::currentUser()->id());
- }
- else {
- $node->setNewRevision(FALSE);
- }
- }
-
- /**
* Form submission handler for the 'preview' action.
*
* @param $form