0

I have been working on a custom field plugin with which the aim is to create a custom field to be used for content and will consist of a link field and a file field through which a thumb image is to be uploaded. I'm ok with the first part is i.e. the link field for which I have declared a uri data definition with a varchar storage schema and a url type for the form element. But I cannot (based on the available documentation) figure out the proper way to manage the file field. I have used a managed_field type as for the form element but cannot figure out what is the correct datatype and storage schema to use.

Edit: The documentation I have found deals with three parts,

  1. The field class where the propertyDefinitions method is overridden and the properties are defined (ex. $properties['link'] = DataDefinition::create('uri')->setLabel(t('Video Link'));)

  2. Also in the field class where the schema method is overridden and the storage properties are defined (ex. $columns['link'] = [ 'type' => 'varchar', 'length' => 255, ];)

  3. the widget class where the formElement method is overridden to define the input form (ex. $element['link'] = [ '#type' => 'url', '#title' => t('Link'), '#default_value' => isset($items[$delta]->link) ? $items[$delta]->link : null, '#empty_value' => '', '#placeholder' => t('Insert a url'), ];)

what should the equivalent parts for an image/file field property be defined?

any input would be appreciated, thanks

0

Why don't you try the Paragraphs module? This looks like a simple combination existing of field types, which is exactly Paragraphs' point.

0

I hope I understood correctly:

FileItem.php

Have a look at public static function defaultStorageSettings() and public static function schema(FieldStorageDefinitionInterface $field_definition)

  • Hi Dumitru, do you mean that I should be extending the FileItem instead of the FieldItemBase class? I have edited my initial question in order to give more details thanks for your answer – Kostas Jul 3 '18 at 12:32
  • Considering the fact that you want to bundle the file field and the link field, perhaps you should consider the Paragraphs module which @Hudri mentioned, unless you need it done custom. If you need it to be custom-made, then think about providing a field which actually contains both of the fields. This would mean having code like $properties['CUSTOM_LINK_FIELD']['link'] = DataDefinition::create('uri')->setLabel(t('Video Link'));. – Postovan Dumitru Jul 3 '18 at 12:39

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.