You are here

function simplenews_newsletter_get_visible in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_newsletter_get_visible()
  2. 8 simplenews.module \simplenews_newsletter_get_visible()
  3. 7.2 simplenews.module \simplenews_newsletter_get_visible()

Loads all visible newsletters.

Does not include newsletters with the opt-out/opt-in setting set to hidden. It is possible to apply additional conditions.

Parameters

array $conditions: Additional conditions.

Return value

array Filtered newsletter entities.

Related topics

3 calls to simplenews_newsletter_get_visible()
SimplenewsSubscriptionBlock::blockForm in src/Plugin/Block/SimplenewsSubscriptionBlock.php
simplenews_user_view in ./simplenews.module
Implements hook_ENTITY_TYPE_view() for user entity.
SubscriptionsFormBase::getNewsletters in src/Form/SubscriptionsFormBase.php
Returns the newsletters available to select from.

File

./simplenews.module, line 622
Simplenews node handling, sent email, newsletter block and general hooks.

Code

function simplenews_newsletter_get_visible(array $conditions = []) {
  $query = \Drupal::entityQuery('simplenews_newsletter');
  $query
    ->sort('weight');
  foreach ($conditions as $key => $value) {
    $query
      ->condition($key, $value);
  }
  $result = $query
    ->execute();
  return array_filter(Newsletter::loadMultiple($result), function ($n) {
    return $n
      ->isAccessible();
  });
}