3

How to display dynamic allowed values list in drupal 8?

In drupal 6 while creating cck select list, I written php code instead of entering allowed values. The sample code of drupal 6 is as follows :

$query = db_query("SELECT distinct field_x_value as x FROM {node} n, {content_type_y} ctdr , {content_field_x} cfer WHERE n.nid = ctdr.nid and cfer.nid = ctdr.nid and field_x_value is not null and field_user_state_value = %d and n.status = %d and field_environment_value = %d", $user->user_state, 1, $environment);

How to do the same functionality in drupal 8?

2 Answers 2

4

It's not possible to set it in the UI, but it's still possible through code.

If you check the exported configuration for your field, you can see that it has an allowed_values_callback property. Create a custom module, create a function that returns the allowed values, set that property in config and then import the configuration again. Or use drush cedit or a similar tool.

0

You need to create one content reference field with manage fields in content type. Through which you can set default content type or you can set views of reference type in "Reference method" dropdown in CCK configuration field. No need of custom query.

2
  • I migrated drupal 6 to drupal 8 version. So it's not possible to change the existing field type in drupal 8. After migration allowed values list not displayed. So how display dynamic allowed values to my existing cck field in drupal 8.
    – shivak
    May 11, 2016 at 7:04
  • Hi Shivak, I know this is an old post, but I have the same issue..Did you figure out how to add a new value? Jan 8, 2021 at 23:36

Your Answer

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

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