Returns all fields that have cardinality greater than one.
\Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type:
array A list of fields of the paragraph type, e.g. ['field_slides' => 'Slides', 'field_texts' => 'Texts'].
protected function getFieldsByCardinalityGreaterOne(ParagraphsType $paragraphs_type) {
$fields = [];
$field_definitions = $this->entityFieldManager
->getFieldDefinitions('paragraph', $paragraphs_type
->id());
foreach ($field_definitions as $name => $definition) {
if ($field_definitions[$name] instanceof FieldConfigInterface) {
$cardinality = $definition
->getFieldStorageDefinition()
->getCardinality();
if ($cardinality === 1) {
continue;
}
$fields[$name] = $definition
->getLabel();
}
}
return $fields;
}