You are here

function date_recur_update_8204 in Recurring Dates Field 3.x

Same name and namespace in other branches
  1. 8.2 date_recur.install \date_recur_update_8204()
  2. 3.0.x date_recur.install \date_recur_update_8204()
  3. 3.1.x date_recur.install \date_recur_update_8204()

Update view and form display configurations.

File

./date_recur.install, line 213

Code

function date_recur_update_8204(&$sandbox) : void {

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface[] $displays */
  $displays = EntityFormDisplay::loadMultiple();
  foreach ($displays as $display) {
    $components = $display
      ->getComponents();
    foreach ($components as $component => $options) {
      $updated = FALSE;
      $type = $options['type'] ?? NULL;
      if ($type === 'date_recur_default_widget') {

        // Change the ID.
        $options['type'] = 'date_recur_basic_widget';

        // No settings to update.
        $updated = TRUE;
      }

      // Interactive widget did not change ID or settings.
      if ($updated) {
        $display
          ->setComponent($component, $options);
      }
    }
    $display
      ->save();
  }

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays */
  $displays = EntityViewDisplay::loadMultiple();
  foreach ($displays as $display) {
    $components = $display
      ->getComponents();
    foreach ($components as $component => $options) {
      $updated = FALSE;
      $type = $options['type'] ?? NULL;
      if ($type === 'date_recur_default_formatter') {

        // Option: show_next. Unchanged.
        // Option: count_per_item. Unchanged.
        // Option: occurrence_format_type. Unchanged.
        // Option: same_end_date_format_type. Unchanged.
        // Change the ID.
        $options['type'] = 'date_recur_basic_formatter';

        // Option: show_rrule. Changed to 'interpreter'.
        if (isset($options['show_rrule'])) {
          unset($options['show_rrule']);
        }
        $updated = TRUE;
      }
      if ($updated) {
        $display
          ->setComponent($component, $options);
      }
    }
    $display
      ->save();
  }
}