class SubscriptionListBuilder in Mailing List 8
Defines a class to build a listing of subscriptions.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\mailing_list\SubscriptionListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of SubscriptionListBuilder
See also
\Drupal\mailing_list\Entity\Subscription
File
- src/
SubscriptionListBuilder.php, line 20
Namespace
Drupal\mailing_listView source
class SubscriptionListBuilder extends EntityListBuilder {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Contruct a new SubscriptionListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The action storage.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder object.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, AccountInterface $current_user, FormBuilderInterface $form_builder, RequestStack $request_stack) {
parent::__construct($entity_type, $storage);
$this->currentUser = $current_user;
$this->formBuilder = $form_builder;
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager')
->getStorage($entity_type
->id()), $container
->get('current_user'), $container
->get('form_builder'), $container
->get('request_stack'));
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [
'title' => [
'data' => $this
->t('Title'),
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
],
'list' => $this
->t('Mailing list'),
'email' => $this
->t('Email'),
];
if ($this->currentUser
->hasPermission('administer mailing list subscriptions')) {
$header += [
'author' => [
'data' => $this
->t('Author'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
'status' => $this
->t('Status'),
'changed' => [
'data' => $this
->t('Updated'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
];
}
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row = [];
/** @var \Drupal\mailing_list\SubscriptionInterface $entity */
if (!$entity
->access('view')) {
return $row;
}
$uri = $entity
->urlInfo();
$options = $uri
->getOptions();
$langcode = $entity
->language()
->getId();
$languages = \Drupal::languageManager()
->getLanguages();
$options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? [
'language' => $languages[$langcode],
] : [];
$uri
->setOptions($options);
$row['title']['data'] = [
'#type' => 'link',
'#title' => $entity
->label(),
'#url' => $uri,
];
$row['list'] = $entity
->getList()
->label();
$row['email']['data'] = [
'#markup' => $entity
->getEmail(),
];
if ($this->currentUser
->hasPermission('administer mailing list subscriptions')) {
$row['author']['data'] = [
'#theme' => 'username',
'#account' => $entity
->getOwner(),
];
$row['status'] = $entity
->isActive() ? $this
->t('Active') : $this
->t('Inactive');
$row['changed'] = \Drupal::service('date.formatter')
->format($entity
->getChangedTime(), 'short');
}
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
// Anonymous users with no session started has no subscription access. We
// return the anonymous subscription access form.
if (!count($build['table']['#rows']) && $this->currentUser
->isAnonymous()) {
return $this->formBuilder
->getForm('\\Drupal\\mailing_list\\Form\\AnonymousSubscriptionAccessForm');
}
$build['table']['#empty'] = $this
->t('No subscriptions found.');
// Prevent search engines from indexing this subscriptions list and pages.
$build['#attached']['html_head'][] = [
[
'#tag' => 'meta',
'#attributes' => [
'name' => 'robots',
'content' => 'noindex,nofollow',
],
],
'mailing_list',
];
return $build;
}
/**
* {@inheritdoc}
*/
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery()
->sort($this->entityType
->getKey('id'));
// Filter by email address for anonymous users when come from a hashed
// access link.
if ($this->currentUser
->isAnonymous() && ($sid = $this->requestStack
->getMasterRequest()
->get('mailing_list_subscription')) && ($subscription = $this
->getStorage()
->load($sid))) {
$query
->condition('email', $subscription
->getEmail());
}
// Only add the pager if a limit is specified.
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
}
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:: |
public | function | Builds a renderable list of operation links for the entity. | 2 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Gets this list's default operations. | 2 |
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 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
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. | |
SubscriptionListBuilder:: |
protected | property | The current user. | |
SubscriptionListBuilder:: |
protected | property | The form builder. | |
SubscriptionListBuilder:: |
protected | property | The request stack. | |
SubscriptionListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides EntityListBuilder:: |
|
SubscriptionListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: |
|
SubscriptionListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: |
|
SubscriptionListBuilder:: |
protected | function |
Loads entity IDs using a pager sorted by the entity id. Overrides EntityListBuilder:: |
|
SubscriptionListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: |
|
SubscriptionListBuilder:: |
public | function |
Contruct a new SubscriptionListBuilder object. Overrides EntityListBuilder:: |