Commit fe04a346 authored by bojanz's avatar bojanz

Remove unneeded line item code.

- Revisions
- List builder
- Copy-pasted order form code.
parent 002f20cc
......@@ -22,13 +22,9 @@ use Drupal\user\UserInterface;
* id = "commerce_line_item",
* label = @Translation("Line Item"),
* handlers = {
* "list_builder" = "Drupal\commerce_line_item\LineItemListBuilder",
* "views_data" = "Drupal\views\EntityViewsData",
* "form" = {
* "default" = "Drupal\commerce_line_item\Form\LineItemForm",
* "add" = "Drupal\commerce_line_item\Form\LineItemForm",
* "edit" = "Drupal\commerce_line_item\Form\LineItemForm",
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm"
* }
* },
* base_table = "commerce_line_item",
......@@ -37,7 +33,6 @@ use Drupal\user\UserInterface;
* entity_keys = {
* "id" = "line_item_id",
* "uuid" = "uuid",
* "revision" = "revision_id",
* "bundle" = "type"
* },
* links = {
......@@ -74,27 +69,6 @@ class LineItem extends ContentEntityBase implements LineItemInterface {
if (!$this->getOwner()) {
$this->setOwnerId(\Drupal::currentUser()->id());
}
// If no revision author has been set explicitly, make the line item owner the
// revision author.
if (!$this->getRevisionAuthor()) {
$this->setRevisionAuthorId($this->getOwnerId());
}
}
/**
* {@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 line item without adding a new revision, we
// need to make sure $entity->revision_log is reset whenever it is empty.
// Therefore, this code allows us to avoid clobbering an existing log
// entry with an empty one.
$record->revision_log = $this->original->revision_log->value;
}
}
/**
......@@ -171,36 +145,6 @@ class LineItem extends ContentEntityBase implements LineItemInterface {
return $this;
}
/**
* {@inheritdoc}
*/
public function getRevisionCreationTime() {
return $this->get('revision_timestamp')->value;
}
/**
* {@inheritdoc}
*/
public function setRevisionCreationTime($timestamp) {
$this->set('revision_timestamp', $timestamp);
return $this;
}
/**
* {@inheritdoc}
*/
public function getRevisionAuthor() {
return $this->get('revision_uid')->entity;
}
/**
* {@inheritdoc}
*/
public function setRevisionAuthorId($uid) {
$this->set('revision_uid', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -231,12 +175,6 @@ class LineItem extends ContentEntityBase implements LineItemInterface {
->setDescription(t('The line item UUID.'))
->setReadOnly(TRUE);
$fields['revision_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Revision ID'))
->setDescription(t('The line item revision ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['type'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The line item type.'))
......@@ -339,32 +277,6 @@ class LineItem extends ContentEntityBase implements LineItemInterface {
->setLabel(t('Data'))
->setDescription(t('A serialized array of additional data.'));
$fields['revision_timestamp'] = BaseFieldDefinition::create('created')
->setLabel(t('Revision timestamp'))
->setDescription(t('The time that the current revision was created.'))
->setQueryable(FALSE)
->setRevisionable(TRUE);
$fields['revision_uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user ID'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setQueryable(FALSE)
->setRevisionable(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;
}
......
......@@ -17,14 +17,8 @@ class LineItemForm extends ContentEntityForm {
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$this->entity->save();
drupal_set_message($this->t('The order %order_label has been successfully saved.', array('%order_label' => $this->entity->label())));
}
catch (\Exception $e) {
drupal_set_message($this->t('The order %order_label could not be saved.', array('%order_label' => $this->entity->label())), 'error');
$this->logger('commerce_line_item')->error($e);
}
$this->entity->save();
drupal_set_message($this->t('The line item %label has been successfully saved.', array('%label' => $this->entity->label())));
$form_state->setRedirect('entity.commerce_line_item.collection');
}
......@@ -32,80 +26,7 @@ class LineItemForm extends ContentEntityForm {
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
/* @var \Drupal\commerce_line_item\Entity\LineItem $order */
$order = $this->entity;
$currentUser = $this->currentUser();
$form['advanced'] = array(
'#type' => 'vertical_tabs',
'#attributes' => array('class' => array('entity-meta')),
'#weight' => 99,
);
$form = parent::form($form, $form_state);
$form['order_status'] = array(
'#type' => 'details',
'#title' => t('Order status'),
'#group' => 'advanced',
'#attributes' => array(
'class' => array('order-form-order-status'),
),
'#attached' => array(
'library' => array('commerce_line_item/drupal.commerce_line_item'),
),
'#weight' => 90,
'#optional' => TRUE,
);
if (isset($form['status'])) {
$form['status']['#group'] = 'order_status';
}
$form['revision'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Create new revision'),
'#default_value' => $order->isNewRevision(),
'#access' => $currentUser->hasPermission('administer line items'),
'#group' => 'order_status',
'#weight' => 10,
);
$form['revision_log'] += array(
'#states' => array(
'visible' => array(
':input[name="revision"]' => array('checked' => TRUE),
),
),
'#group' => 'order_status',
);
// Order authoring information for administrators.
$form['author'] = array(
'#type' => 'details',
'#title' => t('Authoring information'),
'#group' => 'advanced',
'#attributes' => array(
'class' => array('order-form-author'),
),
'#attached' => array(
'library' => array('commerce_line_item/drupal.commerce_line_item'),
),
'#weight' => 91,
'#optional' => TRUE,
);
if (isset($form['uid'])) {
$form['uid']['#group'] = 'author';
}
if (isset($form['mail'])) {
$form['mail']['#group'] = 'author';
}
if (isset($form['created'])) {
$form['created']['#group'] = 'author';
}
return $form;
}
......
......@@ -60,42 +60,6 @@ interface LineItemInterface extends EntityChangedInterface, EntityInterface, Ent
*/
public function setCreatedTime($timestamp);
/**
* Gets the line item revision creation timestamp.
*
* @return int
* The UNIX timestamp of when this revision was created.
*/
public function getRevisionCreationTime();
/**
* Sets the line item revision creation timestamp.
*
* @param int $timestamp
* The UNIX timestamp of when this revision was created.
*
* @return $this
*/
public function setRevisionCreationTime($timestamp);
/**
* Gets the line item revision author.
*
* @return \Drupal\user\UserInterface
* The user entity for the revision author.
*/
public function getRevisionAuthor();
/**
* Sets the line item revision author.
*
* @param int $uid
* The user ID of the revision author.
*
* @return $this
*/
public function setRevisionAuthorId($uid);
/**
* Gets the additional data stored in this line item.
*
......
<?php
/**
* @file
* Contains \Drupal\commerce_line_item\LineItemListBuilder.
*/
namespace Drupal\commerce_line_item;
use Drupal\commerce_line_item\Entity\LineItemType;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the list builder for line items.
*/
class LineItemListBuilder extends EntityListBuilder {
/**
* The date service.
*
* @var \Drupal\Core\Datetime\DateFormatter
*/
protected $dateFormatter;
/**
* Constructs a new LineItemListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entityType
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Datetime\DateFormatter $dateFormatter
* The date service.
*/
public function __construct(EntityTypeInterface $entityType, EntityStorageInterface $storage, DateFormatter $dateFormatter) {
parent::__construct($entityType, $storage);
$this->dateFormatter = $dateFormatter;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entityType) {
return new static(
$entityType,
$container->get('entity.manager')->getStorage($entityType->id()),
$container->get('date.formatter')
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [
'line_item_id' => [
'data' => $this->t('Line Item ID'),
'class' => [RESPONSIVE_PRIORITY_LOW],
],
'type' => [
'data' => $this->t('Line item type'),
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
],
'owner' => [
'data' => $this->t('Owner'),
'class' => [RESPONSIVE_PRIORITY_LOW],
],
'status' => $this->t('Status'),
'created' => [
'data' => $this->t('Created'),
'class' => [RESPONSIVE_PRIORITY_LOW],
],
'updated' => [
'data' => $this->t('Updated'),
'class' => [RESPONSIVE_PRIORITY_LOW],
],
];
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\commerce_line_item\Entity\LineItem */
$lineItemType = LineItemType::load($entity->bundle());
$row = [
'line_item_id' => $entity->id(),
'type' => SafeMarkup::checkPlain($lineItemType->label()),
'owner' => [
'data' => [
'#theme' => 'username',
'#account' => $entity->getOwner(),
],
],
'status' => $entity->getStatus(),
'created' => $this->dateFormatter->format($entity->getCreatedTime(), 'short'),
'changed' => $this->dateFormatter->format($entity->getChangedTime(), 'short'),
];
return $row + parent::buildRow($entity);
}
}
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