You are here

public static function ParagraphsSets::getSetsOptions in Paragraphs Sets 8.2

Get an array of id => label of available sets.

Return value

array Sets labels, keyed by id.

3 calls to ParagraphsSets::getSetsOptions()
ParagraphsSets::buildSelectSetSelection in src/ParagraphsSets.php
Builds select element for set selection.
paragraphs_sets_field_widget_settings_summary_alter in ./paragraphs_sets.module
Implements hook_field_widget_settings_summary_alter().
paragraphs_sets_field_widget_third_party_settings_form in ./paragraphs_sets.module
Implements hook_field_widget_third_party_settings_form().

File

src/ParagraphsSets.php, line 54

Class

ParagraphsSets
Utitlity class for paragraphs_sets.

Namespace

Drupal\paragraphs_sets

Code

public static function getSetsOptions(array $allowed_paragraphs_types = [], $cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
  $sets_data = static::getSets($allowed_paragraphs_types);
  $opts = [];
  foreach ($sets_data as $k => $set) {
    if ($cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && count($set['paragraphs']) > $cardinality) {

      // Do not add sets having more paragraphs than allowed.
      continue;
    }
    $opts[$k] = $set['label'];
  }
  return $opts;
}