0

I need to get a list of all the boolean fields of the node

My code

 $query = \Drupal::entityQuery('node')
   ->condition('status', NODE_PUBLISHED)
   ->condition('type', 'product')

Please help me

closed as unclear what you're asking by Pierre.Vriens, DRUPWAY, mradcliffe, sanzante, Chapabu Mar 29 '18 at 0:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you know the name of the boolean fields – Jdrupal Mar 26 '18 at 16:16
  • Get the base and bundle field definitions from the node class and loop through them to check what type those fields are? – mradcliffe Mar 28 '18 at 1:36
3

You can get a list of an entity's field definitions with EntityFieldManager::getFieldDefinitions(). You should then have a list of fields defined on that entity and should be able to determine which are the boolean fields.

You can access this via a service like:

$product_field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'product');

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