Skip to content

Instantly share code, notes, and snippets.

View ozin7's full-sized avatar
🎯
Focusing

Mykhailo Hurei ozin7

🎯
Focusing
  • Lviv, Ukraine
  • 12:19 (UTC +03:00)
View GitHub Profile
@ozin7
ozin7 / third_party_settings.php
Created March 17, 2020 17:49
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')),
@ozin7
ozin7 / example_commerce_conditions.php
Last active March 20, 2020 07:46
Drupal 8: Commerce condition form element.
<?php
/**
* Implements hook_form_alter().
*/
function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (in_array($form_id, ['commerce_tax_type_edit_form', 'commerce_tax_type_add_form'])) {
$form['commerce_conditions'] = [
'#type' => 'commerce_conditions',
'#title' => t('Conditions'),
'#default_value' => [],