You are here

public static function ParagraphsSets::getSets in Paragraphs Sets 8.2

Get a list of all available sets.

Parameters

array $allowed_paragraphs_types: Optional list of allowed paragraphs types.

Return value

array List of all Paragraphs Sets.

2 calls to ParagraphsSets::getSets()
ParagraphsSets::getSetsOptions in src/ParagraphsSets.php
Get an array of id => label of available sets.
paragraphs_sets_field_widget_multivalue_form_alter in ./paragraphs_sets.module
Implements hook_field_widget_multivalue_form_alter().

File

src/ParagraphsSets.php, line 26

Class

ParagraphsSets
Utitlity class for paragraphs_sets.

Namespace

Drupal\paragraphs_sets

Code

public static function getSets(array $allowed_paragraphs_types = []) {
  $query = \Drupal::entityQuery('paragraphs_set');
  $config_factory = \Drupal::configFactory();
  $results = $query
    ->execute();
  $sets = [];
  foreach ($results as $id) {

    /** @var \Drupal\Core\Config\ImmutableConfig $config */
    if ($config = $config_factory
      ->get("paragraphs_sets.set.{$id}")) {
      $data = $config
        ->get();

      // Check that all paragraph types in set are allowed in field.
      if (!empty($allowed_paragraphs_types)) {
        $types_filtered = array_intersect(array_column($data['paragraphs'], 'type'), $allowed_paragraphs_types);
        if (count($types_filtered) === count($data['paragraphs'])) {
          $sets[$id] = $data;
        }
      }
    }
  }
  return $sets;
}