You are here

public function RecipientHandlerManager::getOptions in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/RecipientHandler/RecipientHandlerManager.php \Drupal\simplenews\RecipientHandler\RecipientHandlerManager::getOptions()
  2. 3.x src/RecipientHandler/RecipientHandlerManager.php \Drupal\simplenews\RecipientHandler\RecipientHandlerManager::getOptions()

Returns the options for a recipient handler form field.

Parameters

string $newsletter_id: (optional) Restrict to handlers that are valid for the specified newsletter ID.

Return value

array An array with key as handler ID and value as handler label.

File

src/RecipientHandler/RecipientHandlerManager.php, line 47

Class

RecipientHandlerManager
Provides an recipient handler plugin manager.

Namespace

Drupal\simplenews\RecipientHandler

Code

public function getOptions($newsletter_id = NULL) {
  $handlers = $this
    ->getDefinitions();
  $options = [];
  foreach ($handlers as $handler => $settings) {
    $options[$handler] = Xss::filter($settings['title']);
  }
  if ($newsletter_id && ($newsletter = Newsletter::load($newsletter_id))) {
    $allowed_handlers = array_filter($newsletter->allowed_handlers);
    if ($allowed_handlers) {
      $options = array_intersect_key($options, $allowed_handlers);
    }
  }
  return $options;
}