From aa2cfa0bd9dc9bfd02f2049505b5a9fe22531b07 Mon Sep 17 00:00:00 2001 From: s j <sj@1729.be> Date: Sat, 29 Jan 2022 09:18:04 +0100 Subject: [PATCH 1/2] i6854 date format --- ....date_format.shareholder_register_date.yml | 7 ---- config/optional/core.date_format.date.yml | 6 +++ .../src/DividendDistributionListBuilder.php | 38 ++++++++++++++++++- .../src/ShareholderDividendListBuilder.php | 37 +++++++++++++++++- ...areholderRegisterDividendTwigExtension.php | 4 +- .../src/TaxshelterClaimListBuilder.php | 5 +++ .../ShareholderRegisterIntegrityException.php | 6 --- src/ShareTransactionListBuilder.php | 36 +++++++++++++++++- src/ShareholderListBuilder.php | 32 +++++++++++++++- src/ShareholderRegisterFormatterService.php | 2 +- 10 files changed, 152 insertions(+), 21 deletions(-) delete mode 100644 config/install/core.date_format.shareholder_register_date.yml create mode 100644 config/optional/core.date_format.date.yml diff --git a/config/install/core.date_format.shareholder_register_date.yml b/config/install/core.date_format.shareholder_register_date.yml deleted file mode 100644 index 26d99c71..00000000 --- a/config/install/core.date_format.shareholder_register_date.yml +++ /dev/null @@ -1,7 +0,0 @@ -langcode: en -status: true -dependencies: { } -id: shareholder_register_date -label: 'Shareholder Register Date' -locked: false -pattern: Y-m-d diff --git a/config/optional/core.date_format.date.yml b/config/optional/core.date_format.date.yml new file mode 100644 index 00000000..eb799461 --- /dev/null +++ b/config/optional/core.date_format.date.yml @@ -0,0 +1,6 @@ +langcode: en +status: true +dependencies: { } +id: date +label: 'Date' +pattern: Y-m-d diff --git a/modules/shareholder_register_dividend/src/DividendDistributionListBuilder.php b/modules/shareholder_register_dividend/src/DividendDistributionListBuilder.php index 8f024316..bd9122d4 100644 --- a/modules/shareholder_register_dividend/src/DividendDistributionListBuilder.php +++ b/modules/shareholder_register_dividend/src/DividendDistributionListBuilder.php @@ -4,8 +4,14 @@ namespace Drupal\shareholder_register_dividend; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; +use Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface; + +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Defines a class to build a listing of Dividend distribution entities. * @@ -13,10 +19,37 @@ use Drupal\Core\Link; */ class DividendDistributionListBuilder extends EntityListBuilder { + /** + * The shareholder register formatter service. + * + * @var \Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface + */ + protected $formatter; + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity_type.manager')->getStorage($entity_type->id()), + $container->get('shareholder_register.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ShareholderRegisterFormatterServiceInterface $formatter) { + parent::__construct($entity_type, $storage); + $this->formatter = $formatter; + } + /** * {@inheritdoc} */ public function buildHeader() { + $header = []; $header['name'] = $this->t('Name'); $header['date'] = $this->t('Date'); $header['total_gross'] = $this->t('Total Gross'); @@ -29,12 +62,15 @@ class DividendDistributionListBuilder extends EntityListBuilder { */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\shareholder_register_dividend\Entity\DividendDistribution $entity */ + + $row = []; $row['name'] = Link::createFromRoute( $entity->label(), 'entity.dividend_distribution.canonical', ['dividend_distribution' => $entity->id()] ); - $row['date'] = $entity->getDate(); + $row['date'] = $this->formatter->formatDate( + $entity->getDate()); $row['total_gross'] = $entity->get('total_gross')->value; $row['total_net'] = $entity->get('total_net')->value; return $row + parent::buildRow($entity); diff --git a/modules/shareholder_register_dividend/src/ShareholderDividendListBuilder.php b/modules/shareholder_register_dividend/src/ShareholderDividendListBuilder.php index bf9df30c..1b5323d4 100644 --- a/modules/shareholder_register_dividend/src/ShareholderDividendListBuilder.php +++ b/modules/shareholder_register_dividend/src/ShareholderDividendListBuilder.php @@ -4,6 +4,12 @@ namespace Drupal\shareholder_register_dividend; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; + +use Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface; + +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a class to build a listing of Shareholder dividend entities. @@ -12,10 +18,37 @@ use Drupal\Core\Entity\EntityListBuilder; */ class ShareholderDividendListBuilder extends EntityListBuilder { + /** + * The shareholder register formatter service. + * + * @var \Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface + */ + protected $formatter; + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity_type.manager')->getStorage($entity_type->id()), + $container->get('shareholder_register.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ShareholderRegisterFormatterServiceInterface $formatter) { + parent::__construct($entity_type, $storage); + $this->formatter = $formatter; + } + /** * {@inheritdoc} */ public function buildHeader() { + $header = []; $header['distribution'] = $this->t('Distribution'); $header['date'] = $this->t('Date'); $header['shareholder'] = $this->t('Shareholder'); @@ -29,8 +62,10 @@ class ShareholderDividendListBuilder extends EntityListBuilder { */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\shareholder_register_dividend\Entity\ShareholderDividend $entity */ + $row = []; $row['distribution'] = $entity->getDistribution()->getName(); - $row['date'] = $entity->getDistribution()->getDate(); + $row['date'] = $this->formatter->formatDate( + $entity->getDistribution()->getDate()); $row['shareholder'] = $entity->getShareholder()->label(); $row['gross'] = $entity->getGross(); $row['net'] = $entity->getNet(); diff --git a/modules/shareholder_register_dividend/src/TwigExtension/ShareholderRegisterDividendTwigExtension.php b/modules/shareholder_register_dividend/src/TwigExtension/ShareholderRegisterDividendTwigExtension.php index d315b939..6d64f7c0 100644 --- a/modules/shareholder_register_dividend/src/TwigExtension/ShareholderRegisterDividendTwigExtension.php +++ b/modules/shareholder_register_dividend/src/TwigExtension/ShareholderRegisterDividendTwigExtension.php @@ -171,9 +171,9 @@ class ShareholderRegisterDividendTwigExtension extends \Twig_Extension { $shares = Share::loadMultiple($group['share_ids']); $share_names = $this->shareholderRegisterFormatter->sharesToRanges($shares); $start_date_formatted = $this->shareholderRegisterFormatter->formatDate( - $group['start_date'], 'shareholder_register_date'); + $group['start_date']); $end_date_formatted = $this->shareholderRegisterFormatter->formatDate( - $this->shareholderRegisterFormatter->endDateIncl($group['end_date']), 'shareholder_register_date'); + $this->shareholderRegisterFormatter->endDateIncl($group['end_date'])); $share_details[] = "{$start_date_formatted} - {$end_date_formatted}: {$share_names}"; } diff --git a/modules/shareholder_register_taxshelter/src/TaxshelterClaimListBuilder.php b/modules/shareholder_register_taxshelter/src/TaxshelterClaimListBuilder.php index 4683b466..5f8eb2d9 100644 --- a/modules/shareholder_register_taxshelter/src/TaxshelterClaimListBuilder.php +++ b/modules/shareholder_register_taxshelter/src/TaxshelterClaimListBuilder.php @@ -48,9 +48,11 @@ class TaxshelterClaimListBuilder extends EntityListBuilder { * {@inheritdoc} */ public function buildHeader() { + $header = []; $header['shareholder'] = $this->t('Shareholder'); $header['year'] = $this->t('Year'); $header['type'] = $this->t('Type'); + $header['date'] = $this->t('Investment Date'); $header['shares'] = $this->t('Shares'); $header['amount'] = $this->t('Amount'); return $header + parent::buildHeader(); @@ -60,9 +62,12 @@ class TaxshelterClaimListBuilder extends EntityListBuilder { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { + $row = []; $row['shareholder'] = $entity->getShareholder()->label(); $row['year'] = $entity->getYear(); $row['type'] = $entity->getType(); + $row['date'] = $this->shareholderRegisterFormatter->formatDate( + $entity->getDate()); $row['shares'] = $this->shareholderRegisterFormatter->sharesToRanges( $entity->getShares()); $row['amount'] = $entity->getAmount(); diff --git a/src/Exception/ShareholderRegisterIntegrityException.php b/src/Exception/ShareholderRegisterIntegrityException.php index 4215d79f..357ac16f 100644 --- a/src/Exception/ShareholderRegisterIntegrityException.php +++ b/src/Exception/ShareholderRegisterIntegrityException.php @@ -20,23 +20,17 @@ class ShareholderRegisterIntegrityException extends ShareholderRegisterException case DELETE_VALID_GROUP: return t('You cannot delete a valid transaction group!'); - break; case DELETE_VALID_TRANSACTION: return t('You cannot delete a valid transaction!'); - break; case DELETE_VALID_SHARE: return t('You cannot delete an issued share!'); - break; case DELETE_VALID_SHAREHOLDER: return t('You cannot delete a valid shareholder!'); - break; - default: return t('Shareholder Register Integrity Exception'); - break; } } diff --git a/src/ShareTransactionListBuilder.php b/src/ShareTransactionListBuilder.php index 1c9fe17d..e29b010d 100644 --- a/src/ShareTransactionListBuilder.php +++ b/src/ShareTransactionListBuilder.php @@ -4,8 +4,12 @@ namespace Drupal\shareholder_register; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Defines a class to build a listing of Share transaction entities. * @@ -13,10 +17,37 @@ use Drupal\Core\Link; */ class ShareTransactionListBuilder extends EntityListBuilder { + /** + * The shareholder register formatter service. + * + * @var \Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface + */ + protected $formatter; + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity_type.manager')->getStorage($entity_type->id()), + $container->get('shareholder_register.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ShareholderRegisterFormatterServiceInterface $formatter) { + parent::__construct($entity_type, $storage); + $this->formatter = $formatter; + } + /** * {@inheritdoc} */ public function buildHeader() { + $header = []; $header['name'] = $this->t('Transaction Number'); $header['date'] = $this->t('Transaction Date'); $header['payment_date'] = $this->t('Date of Payment'); @@ -39,13 +70,14 @@ class ShareTransactionListBuilder extends EntityListBuilder { $shareholder = $entity->getShareholder(); $issue = $entity->getShareIssue(); + $row = []; $row['name'] = Link::createFromRoute( $entity->label(), 'entity.share_transaction.canonical', ['share_transaction' => $entity->id()] ); - $row['date'] = $entity->getDate(); - $row['payment_date'] = $entity->getPaymentDate(); + $row['date'] = $this->formatter->formatDate($entity->getDate()); + $row['payment_date'] = $this->formatter->formatDate($entity->getPaymentDate()); $row['shareholder_number'] = $shareholder ? $shareholder->getNumber() : ''; $row['name'] = $shareholder ? $shareholder->getName() : ''; $row['quantity'] = $entity->getQuantity(); diff --git a/src/ShareholderListBuilder.php b/src/ShareholderListBuilder.php index 1a078740..e7eb962e 100644 --- a/src/ShareholderListBuilder.php +++ b/src/ShareholderListBuilder.php @@ -4,8 +4,12 @@ namespace Drupal\shareholder_register; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Defines a class to build a listing of Shareholder entities. * @@ -13,6 +17,32 @@ use Drupal\Core\Link; */ class ShareholderListBuilder extends EntityListBuilder { + /** + * The shareholder register formatter service. + * + * @var \Drupal\shareholder_register\ShareholderRegisterFormatterServiceInterface + */ + protected $formatter; + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity_type.manager')->getStorage($entity_type->id()), + $container->get('shareholder_register.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ShareholderRegisterFormatterServiceInterface $formatter) { + parent::__construct($entity_type, $storage); + $this->formatter = $formatter; + } + /** * {@inheritdoc} */ @@ -44,7 +74,7 @@ class ShareholderListBuilder extends EntityListBuilder { ); $row['identifier'] = $entity->getIdentifier(); $row['mail'] = $entity->getMail(); - $row['date_of_registration'] = $entity->getRegistrationDate(); + $row['date_of_registration'] = $this->formatter->formatDate($entity->getRegistrationDate()); $row['number_of_shares_held'] = $entity->getShareCount(); $row['value_of_shares_held'] = $entity->getShareTotalValue(); $row['shares'] = \Drupal::service('shareholder_register.formatter')->shareIdsToRanges( diff --git a/src/ShareholderRegisterFormatterService.php b/src/ShareholderRegisterFormatterService.php index 4b3f4009..31dcfb16 100644 --- a/src/ShareholderRegisterFormatterService.php +++ b/src/ShareholderRegisterFormatterService.php @@ -103,7 +103,7 @@ class ShareholderRegisterFormatterService implements ShareholderRegisterFormatte return $this->dateFormatter->format( is_numeric($date) ? $date : strtotime($date), - 'shareholder_register_date', + 'date', '', NULL, $langcode -- GitLab From fa52709e53ef60327b0a19bc9f105739fcb2cdbd Mon Sep 17 00:00:00 2001 From: s j <sj@1729.be> Date: Sun, 30 Jan 2022 07:50:29 +0100 Subject: [PATCH 2/2] i6854 change datetime field settings --- .../src/Entity/DividendDistribution.php | 5 ++++- src/Entity/ShareTransaction.php | 10 ++++++++-- src/Entity/ShareTransactionGroup.php | 5 ++++- src/Entity/Shareholder.php | 10 ++++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/shareholder_register_dividend/src/Entity/DividendDistribution.php b/modules/shareholder_register_dividend/src/Entity/DividendDistribution.php index 6f764a70..99a12da8 100644 --- a/modules/shareholder_register_dividend/src/Entity/DividendDistribution.php +++ b/modules/shareholder_register_dividend/src/Entity/DividendDistribution.php @@ -221,7 +221,10 @@ class DividendDistribution extends ContentEntityBase implements DividendDistribu ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 2, ]) ->setDisplayOptions('form', [ diff --git a/src/Entity/ShareTransaction.php b/src/Entity/ShareTransaction.php index 89fd89df..c0673afc 100644 --- a/src/Entity/ShareTransaction.php +++ b/src/Entity/ShareTransaction.php @@ -572,7 +572,10 @@ class ShareTransaction extends ContentEntityBase implements ShareTransactionInte ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 0, ]) ->setDisplayOptions('form', [ @@ -592,7 +595,10 @@ class ShareTransaction extends ContentEntityBase implements ShareTransactionInte ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 4, ]) ->setDisplayOptions('form', [ diff --git a/src/Entity/ShareTransactionGroup.php b/src/Entity/ShareTransactionGroup.php index fc54a384..dfe64cbb 100644 --- a/src/Entity/ShareTransactionGroup.php +++ b/src/Entity/ShareTransactionGroup.php @@ -287,7 +287,10 @@ class ShareTransactionGroup extends ContentEntityBase implements ShareTransactio ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 0, ]) ->setDisplayOptions('form', [ diff --git a/src/Entity/Shareholder.php b/src/Entity/Shareholder.php index 81dd9ffc..5cf23ee1 100644 --- a/src/Entity/Shareholder.php +++ b/src/Entity/Shareholder.php @@ -614,7 +614,10 @@ class Shareholder extends RevisionableContentEntityBase implements ShareholderIn ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 4, ]) ->setDisplayOptions('form', [ @@ -681,7 +684,10 @@ class Shareholder extends RevisionableContentEntityBase implements ShareholderIn ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', - 'type' => 'string', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], 'weight' => 8, ]) ->setDisplayOptions('form', [ -- GitLab