You are here

function thunder_update_8001 in Thunder 8.2

Adds metatag configuration.

File

./thunder.install, line 112
Install, update and uninstall functions for the thunder installation profile.

Code

function thunder_update_8001() {
  \Drupal::service('module_installer')
    ->install([
    'config_update',
    'metatag_open_graph',
    'metatag_twitter_cards',
  ]);
  $configs = [
    'metatag_defaults' => [
      'node__article',
    ],
    'image_style' => [
      'twitter',
      'facebook',
    ],
  ];
  foreach ($configs as $entity => $ids) {
    foreach ($ids as $id) {
      try {
        \Drupal::service('config_update.config_update')
          ->import($entity, $id);
      } catch (EntityStorageException $e) {
      }
    }
  }
  $meta = MetatagDefaults::load('global');
  $tags = $meta
    ->get('tags');
  if (empty($tags['og_site_name'])) {
    $tags['og_site_name'] = '[site:name]';
  }
  if (empty($tags['twitter_cards_type'])) {
    $tags['twitter_cards_type'] = 'summary';
  }
  $meta
    ->set('tags', $tags);
  $meta
    ->save();
}