You are here

function rrssb_update_8201 in Ridiculously Responsive Social Sharing Buttons 8.2

Update to multiple button sets.

File

./rrssb.install, line 57
Contains install and update functions.

Code

function rrssb_update_8201() {
  \Drupal::entityDefinitionUpdateManager()
    ->installEntityType(new ConfigEntityType([
    'id' => 'rrssb_button_set',
    'label' => new TranslatableMarkup('RRSSB Button Set'),
    'handlers' => [
      'list_builder' => 'Drupal\\rrssb\\RRSSBListBuilder',
      'form' => [
        'add' => 'Drupal\\rrssb\\Form\\RRSSBSettingsForm',
        'edit' => 'Drupal\\rrssb\\Form\\RRSSBSettingsForm',
        'delete' => 'Drupal\\rrssb\\Form\\RRSSBDeleteForm',
      ],
    ],
    'config_prefix' => 'button_set',
    'admin_permission' => 'administer rrssb',
    'entity_keys' => [
      'id' => 'id',
      'label' => 'label',
    ],
    'links' => [
      'edit-form' => '/admin/config/content/rrssb/{button_set}',
      'delete-form' => '/admin/config/content/rrssb/{button_set}/delete',
      'collection' => '/admin/config/content/rrssb',
    ],
  ]));
  $config = \Drupal::config('rrssb.settings')
    ->get();
  $config['id'] = 'default';
  $config['label'] = 'Default';
  \Drupal::entityTypeManager()
    ->getStorage('rrssb_button_set')
    ->create($config)
    ->save();
  foreach (NodeType::loadMultiple() as $type) {
    $enabled = $type
      ->getThirdPartySetting('rrssb', 'show', FALSE);
    $type
      ->unsetThirdPartySetting('rrssb', 'show');
    $type
      ->setThirdPartySetting('rrssb', 'button_set', $enabled ? 'default' : '')
      ->save();
  }
  $blockIds = \Drupal::entityQuery('block')
    ->condition('plugin', 'rrssb_block')
    ->execute();
  foreach (Block::loadMultiple($blockIds) as $block) {
    $settings = $block
      ->get('settings');
    $settings['button_set'] = 'default';
    $block
      ->set('settings', $settings);
    $block
      ->save();
  }
  \Drupal::configFactory()
    ->getEditable('rrssb.settings')
    ->delete();
  \Drupal::cache()
    ->delete('rrssb_buttons');
  rrssb_cache_flush();
}