How do I add fields to an existing custom entity? I have a custom entity that fieldable. I need to add a field to it, and I want to do it through the UI. The entity was created in a custom module, which I can modify.
How can I make the entity fieldable?
/**
 * Defines the Quiz entity.
 *
 * @ingroup qwizard
 *
 * @ContentEntityType(
 *   id = &quot;qwiz&quot;,
 *   label = @Translation(&quot;Quiz&quot;),
 *   bundle_label = @Translation(&quot;Quiz type&quot;),
 *   handlers = {
 *     &quot;storage&quot; = &quot;Drupal\qwizard\QwizStorage&quot;,
 *     &quot;view_builder&quot; = &quot;Drupal\Core\Entity\EntityViewBuilder&quot;,
 *     &quot;list_builder&quot; = &quot;Drupal\qwizard\QwizListBuilder&quot;,
 *     &quot;views_data&quot; = &quot;Drupal\qwizard\Entity\QwizViewsData&quot;,
 *
 *     &quot;form&quot; = {
 *       &quot;default&quot; = &quot;Drupal\qwizard\Form\QwizForm&quot;,
 *       &quot;add&quot; = &quot;Drupal\qwizard\Form\QwizForm&quot;,
 *       &quot;edit&quot; = &quot;Drupal\qwizard\Form\QwizForm&quot;,
 *       &quot;delete&quot; = &quot;Drupal\qwizard\Form\QwizDeleteForm&quot;,
 *     },
 *     &quot;access&quot; = &quot;Drupal\qwizard\QwizAccessControlHandler&quot;,
 *     &quot;route_provider&quot; = {
 *       &quot;html&quot; = &quot;Drupal\qwizard\QwizHtmlRouteProvider&quot;,
 *     },
 *   },
 *   base_table = &quot;qwiz&quot;,
 *   revision_table = &quot;qwiz_revision&quot;,
 *   revision_data_table = &quot;qwiz_field_revision&quot;,
 *   admin_permission = &quot;administer quiz entities&quot;,
 *   entity_keys = {
 *     &quot;id&quot; = &quot;id&quot;,
 *     &quot;revision&quot; = &quot;vid&quot;,
 *     &quot;bundle&quot; = &quot;type&quot;,
 *     &quot;label&quot; = &quot;name&quot;,
 *     &quot;uuid&quot; = &quot;uuid&quot;,
 *     &quot;uid&quot; = &quot;user_id&quot;,
 *     &quot;langcode&quot; = &quot;langcode&quot;,
 *     &quot;status&quot; = &quot;status&quot;,
 *   },
 *   links = {
 *     &quot;canonical&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}&quot;,
 *     &quot;add-page&quot; = &quot;/admin/structure/qwizard/qwiz/add&quot;,
 *     &quot;add-form&quot; = &quot;/admin/structure/qwizard/qwiz/add/{qwiz_type}&quot;,
 *     &quot;edit-form&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/edit&quot;,
 *     &quot;delete-form&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/delete&quot;,
 *     &quot;version-history&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/revisions&quot;,
 *     &quot;revision&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/revisions/{qwiz_revision}/view&quot;,
 *     &quot;revision_revert&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/revisions/{qwiz_revision}/revert&quot;,
 *     &quot;revision_delete&quot; = &quot;/admin/structure/qwizard/qwiz/{qwiz}/revisions/{qwiz_revision}/delete&quot;,
 *     &quot;collection&quot; = &quot;/admin/structure/qwizard/qwiz&quot;,
 *   },
 *   bundle_entity_type = &quot;qwiz_type&quot;,
 *   field_ui_base_route = &quot;entity.qwiz_type.edit_form&quot;
 * )
 */
You just need to add a field_ui_base_route to the entity annotation. The value should be the route ID for the edit form of the config entity type used to provide the bundles.
So if your entity ID is foo and the bundle config entity ID is foo_type, that would be:
@ContentEntityType(
  id = &quot;foo&quot;,
  ...
  field_ui_base_route = &quot;entity.foo_type.edit_form&quot;
)

Rebuild the cache, and you should see the relevant menu links and tabs when you manage your bundles in the UI.