public function configSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    $original = $config->getOriginal();
    // Skip new and not theme config.
    if (empty($original) || ($config->getName() !== 'system.theme')) {
      return;
    }
    $originalTheme = $original['default'];
    $updatedTheme = $config->get('default');

    // Act only with default theme changes.
    if ($originalTheme == $updatedTheme || !in_array($updatedTheme, ['openy_rose', 'openy_lily'])) {
      return;
    }

    // Delete previous theme menu link.
    $originalMenuName = ($originalTheme == 'openy_lily') ? 'main' : 'account';
    $query = $this->connection->select('menu_link_content_data', 'm');
    $query->condition('bundle', 'menu_link_content');
    $query->condition('enabled', 1);
    $query->condition('m.menu_name', $originalMenuName);
    $query->condition('title', "%Language%", 'LIKE');
    $query->condition('link__options', "%language%", 'LIKE');
    $query->fields('m', ['id']);
    $res = $query->execute()->fetchField();
    if (!empty($res)) {
      $menuLink = MenuLinkContent::load($res);
      $menuLink->delete();
    }

    // Create new menu link.
    $updatedMenuName = ($updatedTheme == 'openy_lily') ? 'main' : 'account';
    $menuLink = MenuLinkContent::create([
      'title' => t('Language'),
      'link' => [
        'uri' => 'internal:/',
        'options' => [
          'attributes' => [
            'class' => ['language hidden-md hidden-lg d-block d-md-none'],
          ],
        ],
      ],
      'menu_name' => $updatedMenuName,
      'weight' => 50,
    ]);
    $menuLink->save();
  }
public function configSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    $original = $config->getOriginal();
    // Skip new and not theme config.
    if (empty($original) || ($config->getName() !== 'system.theme')) {
      return;
    }
    $originalTheme = $original['default'];
    $updatedTheme = $config->get('default');

    // Act only with default theme changes.
    if ($originalTheme == $updatedTheme || !in_array($updatedTheme, ['openy_rose', 'openy_lily'])) {
      return;
    }

    // Delete previous theme menu link.
    $originalMenuName = ($originalTheme == 'openy_lily') ? 'main' : 'account';
    $query = $this->connection->select('menu_link_content_data', 'm');
    $query->condition('bundle', 'menu_link_content');
    $query->condition('enabled', 1);
    $query->condition('m.menu_name', $originalMenuName);
    $query->condition('title', "%Language%", 'LIKE');
    $query->condition('link__options', "%language%", 'LIKE');
    $query->fields('m', ['id']);
    $res = $query->execute()->fetchField();
    if (!empty($res)) {
      $menuLink = MenuLinkContent::load($res);
      $menuLink->delete();
    }

    // Create new menu link.
    $updatedMenuName = ($updatedTheme == 'openy_lily') ? 'main' : 'account';
    $menuLink = MenuLinkContent::create([
      'title' => t('Language'),
      'link' => [
        'uri' => 'internal:/',
        'options' => [
          'attributes' => [
            'class' => ['language hidden-md hidden-lg d-block d-md-none'],
          ],
        ],
      ],
      'menu_name' => $updatedMenuName,
      'weight' => 50,
    ]);
    $menuLink->save();
  }
public function configSave ( ConfigCrudEvent $ event ) { $ config = $ event -> getConfig ( ) ; $ original = $ config -> getOriginal ( ) ; // Skip new and not theme config. if ( empty ( $ original ) || ( $ config -> getName ( ) !== 'system.theme' ) ) { return ; } $ originalTheme = $ original [ 'default' ] ; $ updatedTheme = $ config -> get ( 'default' ) ; // Act only with default theme changes. if ( $ originalTheme == $ updatedTheme || ! in_array ( $ updatedTheme , [ 'openy_rose' , 'openy_lily' ] ) ) { return ; } // Delete previous theme menu link. $ originalMenuName = ( $ originalTheme == 'openy_lily' ) ? 'main' : 'account' ; $ query = $ this -> connection -> select ( 'menu_link_content_data' , 'm' ) ; $ query -> condition ( 'bundle' , 'menu_link_content' ) ; $ query -> condition ( 'enabled' , 1 ) ; $ query -> condition ( 'm.menu_name' , $ originalMenuName ) ; $ query -> condition ( 'title' , "%Language%" , 'LIKE' ) ; $ query -> condition ( 'link__options' , "%language%" , 'LIKE' ) ; $ query -> fields ( 'm' , [ 'id' ] ) ; $ res = $ query -> execute ( ) -> fetchField ( ) ; if ( ! empty ( $ res ) ) { $ menuLink = MenuLinkContent :: load ( $ res ) ; $ menuLink -> delete ( ) ; } // Create new menu link. $ updatedMenuName = ( $ updatedTheme == 'openy_lily' ) ? 'main' : 'account' ; $ menuLink = MenuLinkContent :: create ( [ 'title' => t ( 'Language' ) , 'link' => [ 'uri' => 'internal:/' , 'options' => [ 'attributes' => [ 'class' => [ 'language hidden-md hidden-lg d-block d-md-none' ] , ] , ] , ] , 'menu_name' => $ updatedMenuName , 'weight' => 50 , ] ) ; $ menuLink -> save ( ) ; }
React to a config object being saved.

@param \Drupal\Core\Config\ConfigCrudEvent $event
Config crud event.
React to a config object being saved .