0

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')
  ->setLabel(t('Charges'))
  ->setDescription(t('The events charges in Ksh.'))
  ->setRevisionable(TRUE)
  ->setSettings([
    'max_length' => 750,
    'text_processing' => 0,
  ])
  ->setDefaultValue('')
  ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ])
  ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -4,
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);
3
  • 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.