Skip to content

Instantly share code, notes, and snippets.

@ozin7
Created March 17, 2020 17:49
Show Gist options
  • Save ozin7/47b36772c4e1ed9b754eb00dca8ac298 to your computer and use it in GitHub Desktop.
Save ozin7/47b36772c4e1ed9b754eb00dca8ac298 to your computer and use it in GitHub Desktop.
Drupal 8: How to add third party settings which will be saved automatically.
<?php
/**
* Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
*/
function datalayer_form_field_config_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$field = $form_state->getFormObject()->getEntity();
$form['third_party_settings']['datalayer']['label'] = [
'#type' => 'textfield',
'#title' => t('DataLayer label'),
'#default_value' => $field->getThirdPartySetting('datalayer', 'label', $field->get('field_name')),
'#description' => t('Enter the label you would like in the datalayer output.'),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment