I have a field that stores a json string with keys and values in the database. I wish to format this output from my field definition display option to output the json string as a list. Is it possible to achieve this via such an approach?

    $fields['charges'] = BaseFieldDefinition::create('string')
  ->setDescription(t('The events charges in Ksh.'))
    'max_length' => 750,
    'text_processing' => 0,
  ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -4,
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);
  • Is this question specific to base fields or are you looking for a field formatter in general which supports this kind of output? – 4k4 Mar 4 '20 at 16:14
  • Basefields if possible, a (custom) formatter would be the second option ..., – Nicholas Mar 4 '20 at 16:17
  • 1
    Base fields use formatter the same way configurable fields do. Now you have the formatter with the machine name string set in the base field and you need to find a formatter which supports the output you want. – 4k4 Mar 4 '20 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.