You are here

public function SubscriptionWidget::extractNewsletterIds in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/SubscriptionWidget.php \Drupal\simplenews\Plugin\Field\FieldWidget\SubscriptionWidget::extractNewsletterIds()
  2. 3.x src/Plugin/Field/FieldWidget/SubscriptionWidget.php \Drupal\simplenews\Plugin\Field\FieldWidget\SubscriptionWidget::extractNewsletterIds()

Returns the IDs of the selected or deselected newsletters.

Parameters

array $form_state_value: The value of the widget as returned by FormStateInterface::getValue().

bool $selected: Whether to extract selected (TRUE) or deselected (FALSE) newsletter IDs.

Return value

string[] IDs of selected/deselected newsletters.

Overrides SubscriptionWidgetInterface::extractNewsletterIds

File

src/Plugin/Field/FieldWidget/SubscriptionWidget.php, line 113

Class

SubscriptionWidget
Plugin implementation of the 'simplenews_subscription_select' widget.

Namespace

Drupal\simplenews\Plugin\Field\FieldWidget

Code

public function extractNewsletterIds($form_state_value, $selected = TRUE) {
  $selected_ids = array_map(function ($item) {
    return $item['target_id'];
  }, $form_state_value);
  return $selected ? $selected_ids : array_diff($this->newsletterIds, $selected_ids);
}