Commit 07220954 authored by cspitzlay's avatar cspitzlay Committed by jsacksick
Browse files

Issue #3248745 by cspitzlay, mkalkbrenner: Add "created" and "changed"...

Issue #3248745 by cspitzlay, mkalkbrenner: Add "created" and "changed" timestamps to shipping method entities.
parent 59207068
......@@ -88,3 +88,26 @@ function commerce_shipping_update_8203() {
->setInitialValueFromField('amount');
$entity_definition_update->installFieldStorageDefinition('original_amount', 'commerce_shipment', 'commerce_shipping', $storage_definition);
}
/**
* Add created and changed fields to shipping methods.
*/
function commerce_shipping_update_8204() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$storage_definitions['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time when the shipping method was created.'))
->setTranslatable(TRUE)
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE);
$storage_definitions['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time when the shipping method was last edited.'))
->setTranslatable(TRUE);
foreach ($storage_definitions as $name => $definition) {
$definition_update_manager->installFieldStorageDefinition($name, 'commerce_shipping_method', 'commerce_shipping', $definition);
}
}
......@@ -6,6 +6,7 @@ use Drupal\commerce\ConditionGroup;
use Drupal\commerce\Plugin\Commerce\Condition\ConditionInterface;
use Drupal\commerce\Plugin\Commerce\Condition\ParentEntityAwareInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
......@@ -68,6 +69,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
* )
*/
class ShippingMethod extends ContentEntityBase implements ShippingMethodInterface {
use EntityChangedTrait;
/**
* {@inheritdoc}
......@@ -363,7 +365,34 @@ class ShippingMethod extends ContentEntityBase implements ShippingMethodInterfac
'weight' => 20,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time when the shipping method was created.'))
->setTranslatable(TRUE)
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time when the shipping method was last edited.'))
->setTranslatable(TRUE);
return $fields;
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function setCreatedTime($timestamp) {
$this->set('created', $timestamp);
return $this;
}
}
......@@ -4,6 +4,7 @@ namespace Drupal\commerce_shipping\Entity;
use Drupal\commerce_store\Entity\EntityStoresInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
/**
* Defines the interface for shipping methods.
......@@ -12,7 +13,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
* Implemented as a content entity type to allow each store to have its own
* shipping methods.
*/
interface ShippingMethodInterface extends ContentEntityInterface, EntityStoresInterface {
interface ShippingMethodInterface extends ContentEntityInterface, EntityStoresInterface, EntityChangedInterface {
/**
* Gets the shipping method plugin.
......@@ -125,4 +126,22 @@ interface ShippingMethodInterface extends ContentEntityInterface, EntityStoresIn
*/
public function applies(ShipmentInterface $shipment);
/**
* Gets the shipping method creation timestamp.
*
* @return int
* The shipping method creation timestamp.
*/
public function getCreatedTime();
/**
* Sets the shipping method creation timestamp.
*
* @param int $timestamp
* The shipping method creation timestamp.
*
* @return $this
*/
public function setCreatedTime($timestamp);
}
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