What I want to do is give a possibility to the user to save as many images as he likes. For this, I have created a specific field type

    $fields['photo_ids'] = BaseFieldDefinition::create('map')
  ->setDescription(t('The photo ids of the Item entity.'))
    'max_length' => 50,
    'text_processing' => 0,

here I want to save, add, delete IDs of pictures. Not sure if this is the best approach to this problem. The problem is I can't find the way in Drupal 8 to serialize/deserialize and save these data into the database;

  • Sounds like a multi-value field? – Kevin Nov 26 '18 at 14:57
  • yes I plan to store all picture ids in this field – serj Nov 26 '18 at 14:58
  • Why don't you use the built-in field api and ui? Check "setCardinality" for your BaseFieldDefinition approach. – Rainer Feike Nov 26 '18 at 15:00
  • because I don't know about it :), could share an example or link of how to do it? – serj Nov 26 '18 at 15:03
  • There are plenty on youtube. Search for something like "content type field create drupal 8". – Rainer Feike Nov 26 '18 at 15:04

You should not create your content type programmatically, if there's no special reason. Take a look at any intro like this https://www.youtube.com/watch?v=Nfu6nckjuno - then create a content type and fields with the excellent admin UI.

Serialization to DB is done by the Drupal core.

Your Answer

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

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