I have a custom content type 'project' with a title 'project_no'. I am creating a custom field 'project_reference' to be used in other content types. It has few fields; one of them is an entity reference to 'project'. I have this in my FieldType . php file:

$properties['project_no'] = DataDefinition::create('entity_reference')
  ->setLabel(t('Project No.'))

how to display the widget as a drop list and to have it use auto complete to search/filter in contents of 'project'? I want to be able to enter a character and it will filter the projects that contain that character.

  • I would extend entity reference field type and autocomplete widget from core and add the other (hopefully less complex) properties. – 4k4 Dec 21 '20 at 16:38
  • Thank you for replying.. although answer is very direct, but it is still not clear to me.. I am just beginning to delve in drupal coding. :-) I used drush to generate the custom module for the field, so I am moving forward from there – Salman Dec 22 '20 at 18:54
  • You can only drush generate compound fields with skalar properties. Unless you want to invest some time to investigate how for example the core file module extends entity reference field classes for its own file entity you might want to use paragraphs to combine complex field types. – 4k4 Dec 22 '20 at 20:10
  • If it's a content type, then why not use the standard field UI to add your field? The Manage form display UI should be able to accommodate all of your widget needs. If you need to bundle the field into a project, use Features or just export the config to your module. – Beau Dec 23 '20 at 19:53
  • @4k4 I am willing -and actually doing- investing time googling and searching youtube as well as scanning the core modules source files. But, being new to this with almost no 'proper' background in programming, other than what I taught myself over the years for personal needs and use, this make it a little more difficult to locate the exact information, or sometimes, to under it once located. – Salman Dec 25 '20 at 21:19

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.