class PaymentListBuilder in Payment 8.2
Lists payment entities.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\payment\Entity\Payment\PaymentListBuilder implements PaymentListBuilderInterface
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of PaymentListBuilder
1 file declares its use of PaymentListBuilder
- PaymentListBuilderTest.php in tests/
src/ Unit/ Entity/ Payment/ PaymentListBuilderTest.php
File
- src/
Entity/ Payment/ PaymentListBuilder.php, line 15
Namespace
Drupal\payment\Entity\PaymentView source
class PaymentListBuilder extends EntityListBuilder implements PaymentListBuilderInterface {
/**
* The currency storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $currencyStorage;
/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The ID of the owner to restrict payments by.
*
* @var int|null
* The owner ID or null to allow payments of all owners.
*/
protected $ownerId;
/**
* The redirect destination.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
/** @var static $list_builder */
$list_builder = parent::createInstance($container, $entity_type);
$list_builder->currencyStorage = $container
->get('entity_type.manager')
->getStorage('currency');
$list_builder->dateFormatter = $container
->get('date.formatter');
$list_builder->moduleHandler = $container
->get('module_handler');
$list_builder->redirectDestination = $container
->get('redirect.destination');
$list_builder->stringTranslation = $container
->get('string_translation');
return $list_builder;
}
/**
* Sets the date formatter.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter.
*/
public function setDateFormatter(DateFormatterInterface $date_formatter) {
$this->dateFormatter = $date_formatter;
}
/**
* Sets the currency storage.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $currency_storage
* The currency storage.
*/
public function setCurrencyStorage(EntityStorageInterface $currency_storage) {
$this->currencyStorage = $currency_storage;
}
/**
* {@inheritdoc}
*/
public function restrictByOwnerId($owner_id) {
$this->ownerId = $owner_id;
return $this;
}
/**
* {@inheritdoc}
*/
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery();
$header = $this
->buildHeader();
$query
->tableSort($header);
if ($this->ownerId) {
$query
->condition('owner', $this->ownerId);
}
return $query
->pager($this->limit)
->execute();
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('There are no payments yet.');
return $build;
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['updated'] = [
'data' => $this
->t('Last updated'),
'field' => 'changed',
'sort' => 'DESC',
'specifier' => 'changed',
];
$header['status'] = [
'data' => $this
->t('Status'),
];
$header['amount'] = [
'data' => $this
->t('Amount'),
];
$header['payment_method'] = array(
'data' => $this
->t('Payment method'),
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
);
$header['owner'] = array(
'data' => $this
->t('Payer'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
);
$header['operations'] = [
'data' => $this
->t('Operations'),
];
return $header;
}
/**
* {@inheritdnoc}
*/
public function buildRow(EntityInterface $payment) {
/** @var \Drupal\payment\Entity\PaymentInterface $payment */
$row['data']['updated'] = $this->dateFormatter
->format($payment
->getChangedTime());
$status_definition = $payment
->getPaymentStatus()
->getPluginDefinition();
$row['data']['status'] = $status_definition['label'];
/** @var \Drupal\currency\Entity\CurrencyInterface $currency */
$currency = $this->currencyStorage
->load($payment
->getCurrencyCode());
if (!$currency) {
$currency = $this->currencyStorage
->load('XXX');
}
$row['data']['amount'] = $currency
->formatAmount($payment
->getAmount());
$row['data']['payment_method'] = $payment
->getPaymentMethod() ? $payment
->getPaymentMethod()
->getPluginDefinition()['label'] : $this
->t('Unavailable');
$row['data']['owner']['data'] = array(
'#theme' => 'username',
'#account' => $payment
->getOwner(),
);
$operations = $this
->buildOperations($payment);
$row['data']['operations']['data'] = $operations;
return $row;
}
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
$destination = $this->redirectDestination
->get();
$operations = parent::getDefaultOperations($entity);
foreach ($operations as &$operation) {
$operation['query']['destination'] = $destination;
}
if ($entity
->access('view')) {
$operations['view'] = array(
'title' => $this
->t('View'),
'weight' => -10,
'url' => $entity
->toUrl(),
);
}
if ($entity
->access('update_status')) {
$operations['update_status'] = array(
'title' => $this
->t('Update status'),
'attributes' => array(
'data-accepts' => 'application/vnd.drupal-modal',
),
'query' => array(
'destination' => $destination,
),
'url' => $entity
->toUrl('update-status-form'),
);
}
if ($entity
->access('capture')) {
$operations['capture'] = array(
'title' => $this
->t('Capture'),
'attributes' => array(
'data-accepts' => 'application/vnd.drupal-modal',
),
'query' => array(
'destination' => $destination,
),
'url' => $entity
->toUrl('capture-form'),
);
}
if ($entity
->access('refund')) {
$operations['refund'] = array(
'title' => $this
->t('Refund'),
'attributes' => array(
'data-accepts' => 'application/vnd.drupal-modal',
),
'query' => array(
'destination' => $destination,
),
'url' => $entity
->toUrl('refund-form'),
);
}
if ($entity
->access('complete')) {
$operations['complete'] = array(
'title' => $this
->t('Complete'),
'url' => $entity
->toUrl('complete'),
);
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function buildOperations(EntityInterface $entity) {
$build = parent::buildOperations($entity);
// @todo Remove this when https://drupal.org/node/2253257 is fixed.
$build['#attached'] = array(
'library' => array(
'core/drupal.ajax',
),
);
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Gets the label of an entity. | |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
EntityListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides EntityListBuilderInterface:: |
4 |
EntityListBuilder:: |
public | function | Constructs a new EntityListBuilder object. | 16 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PaymentListBuilder:: |
protected | property | The currency storage. | |
PaymentListBuilder:: |
protected | property | The date formatter. | |
PaymentListBuilder:: |
protected | property | The ID of the owner to restrict payments by. | |
PaymentListBuilder:: |
protected | property |
The redirect destination. Overrides RedirectDestinationTrait:: |
|
PaymentListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
public | function |
Builds a renderable list of operation links for the entity. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
public | function |
{@inheritdnoc} Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
protected | function |
Gets this list's default operations. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
protected | function |
Loads entity IDs using a pager sorted by the entity id. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: |
|
PaymentListBuilder:: |
public | function |
Restricts the displayed payments by owner ID. Overrides PaymentListBuilderInterface:: |
|
PaymentListBuilder:: |
public | function | Sets the currency storage. | |
PaymentListBuilder:: |
public | function | Sets the date formatter. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |