Score:0

user account custom fields list of boolean type

tr flag

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

Score:0
tr flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.