You are here

protected function ParagraphsSliderPlugin::getFieldsByCardinalityGreaterOne in Paragraphs Collection 8

Returns all fields that have cardinality greater than one.

Parameters

\Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type:

Return value

array A list of fields of the paragraph type, e.g. ['field_slides' => 'Slides', 'field_texts' => 'Texts'].

1 call to ParagraphsSliderPlugin::getFieldsByCardinalityGreaterOne()
ParagraphsSliderPlugin::buildConfigurationForm in modules/paragraphs_collection_demo/src/Plugin/paragraphs/Behavior/ParagraphsSliderPlugin.php
Form constructor.

File

modules/paragraphs_collection_demo/src/Plugin/paragraphs/Behavior/ParagraphsSliderPlugin.php, line 314

Class

ParagraphsSliderPlugin
Provides Slider plugin.

Namespace

Drupal\paragraphs_collection_demo\Plugin\paragraphs\Behavior

Code

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;
}