You are here

public function SequentialNumberPatternBase::generate in Commerce Core 8.2

Generates a number for the given content entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity.

Return value

string The generated number.

Overrides NumberPatternBase::generate

File

modules/number_pattern/src/Plugin/Commerce/NumberPattern/SequentialNumberPatternBase.php, line 182

Class

SequentialNumberPatternBase
Provides a base class for number pattern plugins which support sequences.

Namespace

Drupal\commerce_number_pattern\Plugin\Commerce\NumberPattern

Code

public function generate(ContentEntityInterface $entity) {
  $next_sequence = $this
    ->getNextSequence($entity);
  $number = $next_sequence
    ->getNumber();
  if ($this->configuration['padding'] > 0) {
    $number = str_pad($number, $this->configuration['padding'], '0', STR_PAD_LEFT);
  }
  $number = $this->token
    ->replace($this->configuration['pattern'], [
    'pattern' => [
      'number' => $number,
    ],
    $entity
      ->getEntityTypeId() => $entity,
  ]);
  return $number;
}