2

I created a custom content type called 'slide' that has a custom select field called 'field_category'. I would like to be able to load the available options of 'field_category' into the select field of a block form.

I'm currently attempting to follow the instructions of an answer to a similar question here but I'm still having trouble.

I'm grabbing the content type definitions like so

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

However when I spit out

print_r($definitions->getFieldDefinition('field_category'))

I can't actually find any of the options to grab. Is there a way to grab the available options of a field of a custom content type programmatically?

1 Answer 1

7
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'slide');
$definition = $definitions['field_category'];
$settings = $definition->getSettings();
$allowed_values = $settings['allowed_values'];
0

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.