Hello,

I have a requirement, which I know how to achieve in Drupal 7. However, I am not sure of the D8 approach. Below mentioned are the details.

I have following available in my Drupal UI:

  1. Article Content Type
  2. Tags field, Which is provided by default as an entity reference of Taxanomy Term.

Requirement:

  1. Create checkbox element inside the "Edit Form" of Tags field (i.e: field_config_edit_form).
  2. Save this checkbox element value.

Drupal 7 Approach:

  1. Alter the field edit form.
  2. Add the form element as following:
        $form['instance']['test_field_setting'] = array(
          '#type' => 'checkbox',
          '#title' => t('Test Field Setting'),
          '#weight' => -7,
        );
  3. Thats It, Anything mentioned inside $form['instance'] array would used to get saved by Drupal in field_config table.

Drupal 8 Approach: I am not sure about this

  • Alter the form with form ID "field_config_edit_form"
  • Add the form element as following:
        $form['test_field_setting'] = array(
          '#type' => 'checkbox',
          '#title' => t('Test Field Setting'),
          '#weight' => -7,
        );
    
  • Add the custom submit handler.
  • Inside Submit handler, Write code that will how load the "field config" for "Tags Field" and set values for your element inside that config.

I am getting a feeling that this might not be the correct approach to achieve this.

Please let me know if you know a better way or if my approach is not ideal w.r.t Drupal standards.