0

In configuration form i need to create field with dinamic options. this needs to be rendered from user acount custom fields (i have create custom field earlier type of boolean) so i need reneder this field.

I have started from $accountFields = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');

How do i filter out fields with boolean type

1 Answer 1

0

After some research i have done this like this :

$definitions = array_filter(
        \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user'),
        function ($fieldDefinition) {
          return $fieldDefinition instanceof \Drupal\field\FieldConfigInterface;
        }
      );
    $fields = array();
    foreach ($definitions as $field){

        if( $field->getType() === 'boolean') {
            
            $fields[$field->getName()] = $field->getLabel();
        }
    }
    return $fields;

I need it for selection list so the field returns and array field_name => field_label

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.