Commit 605aa3b5 authored by bojanz's avatar bojanz

Remove product revisions.

parent 0e6a72a3
drupal.commerce_product:
version: VERSION
js:
js/commerce_product.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupal.form
......@@ -3,6 +3,5 @@ status: true
dependencies: { }
id: product
label: Product
revision: null
digital: null
description: null
......@@ -8,9 +8,6 @@ commerce_product.commerce_product_type.*:
label:
type: label
label: 'Label'
revision:
type: boolean
label: 'Create new revision'
digital:
type: boolean
label: 'Products of this type represent digital services.'
......
/**
* @file
* Defines Javascript behaviors for the commerce_product module.
*/
(function ($) {
"use strict";
Drupal.behaviors.commerceProductDetailsSummaries = {
attach: function (context) {
var $context = $(context);
$context.find('.product-form-revision-information').drupalSetSummary(function (context) {
var $context = $(context);
var revisionCheckbox = $context.find('.form-item-revision input');
// Return 'New revision' if the 'Create new revision' checkbox is checked,
// or if the checkbox doesn't exist, but the revision log does. For users
// without the "Administer content" permission the checkbox won't appear,
// but the revision log will if the content type is set to auto-revision.
if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $context.find('.form-item-revision-log textarea').length)) {
return Drupal.t('New revision');
}
return Drupal.t('No revision');
});
}
};
})(jQuery);
......@@ -39,14 +39,11 @@ use Drupal\user\UserInterface;
* translatable = TRUE,
* base_table = "commerce_product",
* data_table = "commerce_product_field_data",
* revision_table = "commerce_product_revision",
* revision_data_table = "commerce_product_field_revision",
* entity_keys = {
* "id" = "product_id",
* "label" = "title",
* "langcode" = "langcode",
* "uuid" = "uuid",
* "revision" = "revision_id",
* "bundle" = "type"
* },
* links = {
......@@ -197,20 +194,6 @@ class Product extends ContentEntityBase implements ProductInterface {
return $this->set('uid', $uid);
}
/**
* {@inheritdoc}
*/
public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
parent::preSaveRevision($storage, $record);
if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
// If we are updating an existing product without adding a new
// revision and the user did not supply a revision log, keep the existing
// one.
$record->revision_log = $this->original->getRevisionLog();
}
}
/**
* {@inheritdoc}
*/
......@@ -220,18 +203,11 @@ class Product extends ContentEntityBase implements ProductInterface {
->setDescription(t('The ID of the product.'))
->setReadOnly(TRUE);
$fields['revision_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Revision ID'))
->setDescription(t('The product revision ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['store_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Store'))
->setDescription(t('The store to which the product belongs.'))
->setCardinality(1)
->setRequired(TRUE)
->setRevisionable(TRUE)
->setSetting('target_type', 'commerce_store')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
......@@ -246,7 +222,6 @@ class Product extends ContentEntityBase implements ProductInterface {
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Author'))
->setDescription(t('The user that created this product.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\commerce_product\Entity\Product::getCurrentUserId')
......@@ -275,15 +250,13 @@ class Product extends ContentEntityBase implements ProductInterface {
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of product.'))
->setRevisionable(TRUE);
->setDescription(t('The language code of product.'));
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Title'))
->setDescription(t('The title of this node, always treated as non-markup plain text.'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setSettings([
'default_value' => '',
'max_length' => 255,
......@@ -305,7 +278,6 @@ class Product extends ContentEntityBase implements ProductInterface {
->setRequired(TRUE)
->addConstraint('ProductSku')
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
......@@ -327,7 +299,6 @@ class Product extends ContentEntityBase implements ProductInterface {
->setLabel(t('Active'))
->setDescription(t('Disabled products cannot be added to shopping carts and may be hidden in administrative product lists.'))
->setDefaultValue(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setSettings([
'default_value' => 1,
......@@ -344,7 +315,6 @@ class Product extends ContentEntityBase implements ProductInterface {
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the product was created.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
......@@ -360,39 +330,11 @@ class Product extends ContentEntityBase implements ProductInterface {
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the product was last edited.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['revision_log'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Revision log message'))
->setDescription(t('The log entry explaining the changes in this revision.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDisplayOptions('form', [
'type' => 'string_textarea',
'weight' => 25,
'settings' => [
'rows' => 4,
],
]);
return $fields;
}
/**
* {@inheritdoc}
*/
public function getRevisionLog() {
return $this->get('revision_log')->value;
}
/**
* {@inheritdoc}
*/
public function setRevisionLog($revision_log) {
$this->set('revision_log', $revision_log);
return $this;
}
/**
* Default value callback for 'uid' base field definition.
......
......@@ -36,7 +36,6 @@ use Drupal\commerce_product\ProductTypeInterface;
* config_export = {
* "id",
* "label",
* "revision",
* "digital",
* "description",
* },
......@@ -84,13 +83,6 @@ class ProductType extends ConfigEntityBundleBase implements ProductTypeInterface
*/
protected $digital;
/**
* The default revision setting for products of this type.
*
* @var bool
*/
public $revision;
/**
* Indicates whether a body field should be created for this product type.
*
......
......@@ -15,24 +15,6 @@ use Drupal\Core\Form\FormStateInterface;
*/
class ProductForm extends ContentEntityForm {
/**
* {@inheritdoc}
*
* Fills in a few default values, and then invokes hook_commerce_product_prepare()
* on all modules.
*/
protected function prepareEntity() {
/* @var \Drupal\commerce_product\Entity\Product $product */
$product = $this->entity;
// Set up default values, if required.
$productType = entity_load('commerce_product_type', $product->bundle());
if (!$product->isNew()) {
$product->setRevisionLog(NULL);
}
// Always use the default revision setting.
$product->setNewRevision($productType->revision);
}
/**
* {@inheritdoc}
*/
......@@ -48,42 +30,6 @@ class ProductForm extends ContentEntityForm {
];
$form = parent::form($form, $form_state);
// Add a 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'] = [
'#type' => 'details',
'#group' => 'advanced',
'#title' => t('Revision information'),
// Open by default when "Create new revision" is checked.
'#open' => $product->isNewRevision(),
'#attributes' => [
'class' => ['product-form-revision-information'],
],
'#attached' => [
'library' => ['commerce_product/drupal.commerce_product'],
],
'#weight' => 20,
'#optional' => TRUE,
'#access' => $product->isNewRevision() || $currentUser->hasPermission('administer products'),
];
$form['revision'] = [
'#type' => 'checkbox',
'#title' => $this->t('Create new revision'),
'#default_value' => $product->isNewRevision(),
'#access' => $currentUser->hasPermission('administer products'),
'#group' => 'revision_information',
];
$form['revision_log'] += [
'#states' => [
'visible' => [
':input[name="revision"]' => ['checked' => TRUE],
],
],
'#group' => 'revision_information',
];
// Product author information for administrators.
$form['author'] = [
'#type' => 'details',
......@@ -110,20 +56,6 @@ class ProductForm extends ContentEntityForm {
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
/** @var \Drupal\commerce_product\entity\Product $product */
$product = $this->getEntity();
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('revision')) {
$product->setNewRevision();
}
}
/**
* {@inheritdoc}
*/
......
......@@ -46,12 +46,6 @@ class ProductTypeForm extends EntityForm {
'#default_value' => $productType->isDigital(),
'#description' => t('Products of this type represent digital services.')
];
$form['revision'] = [
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $productType->revision,
'#description' => t('Create a new revision by default for this product type.')
];
return $form;
}
......
......@@ -98,23 +98,4 @@ interface ProductInterface extends EntityStoreInterface, EntityChangedInterface,
*/
public function getType();
/**
* Gets the product revision log message.
*
* @return string
* The revision log message.
*/
public function getRevisionLog();
/**
* Sets the product revision log message.
*
* @param string $revision_log
* The revision log message.
*
* @return \Drupal\commerce_product\ProductInterface
* The class instance that this method is called on.
*/
public function setRevisionLog($revision_log);
}
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