0

I'm trying to figure out how to add an extra field to content type field settings page.

Basically I want to alter field instance settings form on admin/structure/types/manage//fields/node../storage .

I'm going with hook_form_FORM_ID_alter for FORM_ID field_config_edit_form. The new form element appears on the form but after submit I'm not able to see the value.

Am I missing something? Is an extra form submit function required other than the default one to submit my new value?

Here is my snippet -

/** * Implements hook_form_FORM_ID_alter(). */ function mymod_form_field_storage_config_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $form['enabled'] = array( '#type' => 'checkbox', '#title' => t('Enable'), '#description' => t('If enabled then this module will alter the field settings.'), '#default_value' => $form['enabled'], ); } 
2
  • Extra fields in config entities are stored in the ThirdPartySettings, see webomelette.com/… Commented Feb 13, 2019 at 23:30
  • Ok, I can see the use of $form['#entity_builders'][] and ThirdPartySettingsInterface . Will try it out and update here. Commented Feb 14, 2019 at 7:18

1 Answer 1

0

Here is an example -

/** * Implements hook_form_FORM_ID_alter(). */ function mymod_form_field_storage_config_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $form['enabled'] = array( '#type' => 'checkbox', '#title' => t('Enable'), '#description' => t('If enabled then this module will alter the field settings.'), '#default_value' => $form['enabled'], ); $form['#entity_builders'][] = '_my_additional_form_field_storage_submit'; } /** * Entity builder. */ function _my_additional_form_field_storage_submit($entity_type, Drupal\field\Entity\FieldStorageConfig $fieldStorageConfig, &$form, \Drupal\Core\Form\FormStateInterface $form_state) { if ($form_state->getValue('enabled')) { $fieldStorageConfig->setThirdPartySetting('my_additional_settings', 'enabled', $form_state->getValue('enabled')); } return true; } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.