You are here

public function ParagraphsBehaviorBase::getFieldNameOptions in Paragraphs 8

Returns list of field names for the given paragraph type and field type.

Parameters

\Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type: The paragraphs type entity.

string $field_type: (optional) Field type to check for existence. If field type is not provided, returns all entity fields.

Return value

string[] The list of field labels keyed by their field name.

Overrides ParagraphsBehaviorInterface::getFieldNameOptions

1 call to ParagraphsBehaviorBase::getFieldNameOptions()
TestFieldsSelectionBehavior::buildConfigurationForm in tests/modules/paragraphs_test/src/Plugin/paragraphs/Behavior/TestFieldsSelectionBehavior.php
Form constructor.

File

src/ParagraphsBehaviorBase.php, line 180

Class

ParagraphsBehaviorBase

Namespace

Drupal\paragraphs

Code

public function getFieldNameOptions(ParagraphsType $paragraphs_type, $field_type = NULL) {
  $fields = [];
  $field_definitions = $this->entityFieldManager
    ->getFieldDefinitions('paragraph', $paragraphs_type
    ->id());
  foreach ($field_definitions as $name => $definition) {
    if ($field_definitions[$name] instanceof FieldConfigInterface) {
      if (empty($field_type) || $definition
        ->getType() == $field_type) {
        $fields[$name] = $definition
          ->getLabel();
      }
    }
  }
  return $fields;
}