You are here

function better_formats_form_field_config_edit_form_alter in Better Formats 8

Implements hook_form_FORM_ID_alter().

File

./better_formats.module, line 289
Enhances the core input format system by managing input format defaults and settings.

Code

function better_formats_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $entity = $form_state
    ->getFormObject()
    ->getEntity();

  // Only alter fields with text processing and if admin has chosen.
  $text_processing = better_formats_is_text_format($entity
    ->getType());
  $config = Drupal::config('better_formats.settings');
  if ($text_processing && $config
    ->get('per_field_core')) {

    // Add a submit handler to save default values on empty fields.
    $form['actions']['submit']['#submit'][] = 'better_formats_field_config_edit_form_submit';
  }

  // If the field is a format-using text field, allow the admin to configure
  // which formats are allowed here.
  if ($text_processing) {

    // We have to set an explicit weight here so that we can put the allowed
    // formats list after it.
    $betterFormatsSettings = $entity
      ->getThirdPartySettings('better_formats') != NULL ? $entity
      ->getThirdPartySettings('better_formats') : [];

    // Add in the better formats table.
    $form['third_party_settings'] += better_formats_field_settings_form($betterFormatsSettings);
    $form['third_party_settings']['#weight'] = -4;
  }
}