You are here

public function AvatarKitFormAlter::fieldConfigEditFormSubmit in Avatar Kit 8.2

Submission handler for field config edit form alter.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides AvatarKitFormAlterInterface::fieldConfigEditFormSubmit

See also

\Drupal\avatars\AvatarKitFormAlterInterface::fieldConfigEditForm

File

src/AvatarKitFormAlter.php, line 94

Class

AvatarKitFormAlter
Drupal form alters.

Namespace

Drupal\avatars

Code

public function fieldConfigEditFormSubmit(array $form, FormStateInterface $form_state) : void {
  $field_config = $this
    ->getFieldConfig($form_state);
  $hash['contents'] = $form_state
    ->getValue([
    'avatars',
    'hash',
  ]);
  $field_config
    ->setThirdPartySetting('avatars', 'hash', $hash);
  $enabledServices = [];
  $service_info = $form_state
    ->getValue([
    'avatars',
    'services',
  ]);
  foreach ($service_info as $service_id => $info) {
    [
      'status' => $status,
      'weight' => $weight,
    ] = $info;

    // Ignore disabled services.
    if ($status == 'enabled') {
      $enabledServices[$weight] = $service_id;
    }
  }
  ksort($enabledServices, SORT_NUMERIC);
  $field_config
    ->setThirdPartySetting('avatars', 'services', $enabledServices);

  // Reset avatar preferences.
  $entityTypeId = $field_config
    ->getTargetEntityTypeId();
  $bundle = $field_config
    ->getTargetBundle();
  $this
    ->entityPreferenceManager()
    ->invalidatePreferences($field_config
    ->getTargetEntityTypeId(), $bundle);

  // Reset entity render caches.
  $viewTags = [
    $entityTypeId . '_view',
  ];
  $listTags = $this
    ->entityTypeManager()
    ->getDefinition($entityTypeId)
    ->getListCacheTags();
  $tags = Cache::mergeTags($viewTags, $listTags);
  Cache::invalidateTags($tags);
}