Commit edfd0289 authored by bojanz's avatar bojanz

Another round of Store entity cleanups.

- Cleaned up the interface docblocks.
- Removed the redundant owner field description.
- Introduced getDefaultCurrencyCode() and setDefaultCurrencyCode()
- Fixed getDefaultCurrency to return the entity (instead of nothing).
- Added type hinting to setDefaultCurrency(), made it accept an entity.
parent 42d1a5da
......@@ -8,6 +8,7 @@
namespace Drupal\commerce_store\Entity;
use CommerceGuys\Addressing\Enum\AddressField;
use CommerceGuys\Intl\Currency\CurrencyInterface;
use Drupal\address\AddressInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
......@@ -103,23 +104,23 @@ class Store extends ContentEntityBase implements StoreInterface {
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('uid')->target_id;
public function setOwner(UserInterface $account) {
$this->set('uid', $account->id());
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('uid', $uid);
return $this;
public function getOwnerId() {
return $this->get('uid')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('uid', $account->id());
public function setOwnerId($uid) {
$this->set('uid', $uid);
return $this;
}
......@@ -142,13 +143,28 @@ class Store extends ContentEntityBase implements StoreInterface {
* {@inheritdoc}
*/
public function getDefaultCurrency() {
return $this->get('default_currency')->value;
return $this->get('default_currency')->entity;
}
/**
* {@inheritdoc}
*/
public function setDefaultCurrency(CurrencyInterface $currency) {
$this->set('default_currency', $currency->getCurrencyCode());
return $this;
}
/**
* {@inheritdoc}
*/
public function getDefaultCurrencyCode() {
return $this->get('default_currency')->target_id;
}
/**
* {@inheritdoc}
*/
public function setDefaultCurrency($currencyCode) {
public function setDefaultCurrencyCode($currencyCode) {
$this->set('default_currency', $currencyCode);
return $this;
}
......@@ -205,7 +221,6 @@ class Store extends ContentEntityBase implements StoreInterface {
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Owner'))
->setDescription(t('The user that owns this store.'))
->setDefaultValueCallback('Drupal\commerce_store\Entity\Store::getCurrentUserId')
->setSetting('target_type', 'user')
->setDisplayOptions('form', [
......
......@@ -7,6 +7,7 @@
namespace Drupal\commerce_store;
use CommerceGuys\Intl\Currency\CurrencyInterface;
use Drupal\address\AddressInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\EntityOwnerInterface;
......@@ -17,18 +18,18 @@ use Drupal\user\EntityOwnerInterface;
interface StoreInterface extends EntityInterface, EntityOwnerInterface {
/**
* Gets the name of the store.
* Gets the store name.
*
* @return string
* The content of the field.
* The store name.
*/
public function getName();
/**
* Sets the name of the store.
* Sets the store name.
*
* @param string $name
* The new name of the store.
* The store name.
*
* @return \Drupal\commerce_store\StoreInterface
* The class instance that this method is called on.
......@@ -36,18 +37,18 @@ interface StoreInterface extends EntityInterface, EntityOwnerInterface {
public function setName($name);
/**
* Gets the e-mail address of the store.
* Gets the store e-mail.
*
* @return string
* The content of the field.
* The store e-mail
*/
public function getEmail();
/**
* Sets the e-mail address of the store.
* Sets the store e-mail.
*
* @param string $mail
* The new e-mail address of the store.
* The store e-mail.
*
* @return \Drupal\commerce_store\StoreInterface
* The class instance that this method is called on.
......@@ -55,23 +56,42 @@ interface StoreInterface extends EntityInterface, EntityOwnerInterface {
public function setEmail($mail);
/**
* Gets the default currency for the store.
* Gets the default store currency.
*
* @return string
* The content of the field.
* @return \CommerceGuys\Intl\Currency\CurrencyInterface
* The default store currency.
*/
public function getDefaultCurrency();
/**
* Sets the default currency for the store.
* Sets the default store currency.
*
* @param \CommerceGuys\Intl\Currency\CurrencyInterface $currency
* The default store currency.
*
* @return \Drupal\commerce_store\StoreInterface
* The class instance that this method is called on.
*/
public function setDefaultCurrency(CurrencyInterface $currency);
/**
* Gets the default store currency code.
*
* @return string
* The default store currency code.
*/
public function getDefaultCurrencyCode();
/**
* Sets the default store currency code.
*
* @param string $currency_code
* The new default currency code of the store.
* @param string $currencyCode
* The default store currency code.
*
* @return \Drupal\commerce_store\StoreInterface
* The class instance that this method is called on.
*/
public function setDefaultCurrency($currencyCode);
public function setDefaultCurrencyCode($currencyCode);
/**
* Gets the store address.
......
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