You are here

function _breakpoint_delete_breakpoints in Breakpoints 8

Remove breakpoints from all disabled themes or uninstalled modules. The source type has to match the original source type, otherwise the group will not be deleted.

Parameters

array $ids: Identifiers of the breakpoint group.

string $sourceType: Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE.

2 calls to _breakpoint_delete_breakpoints()
breakpoint_modules_uninstalled in ./breakpoint.module
Implements hook_modules_uninstalled().
breakpoint_themes_disabled in ./breakpoint.module
Implements hook_themes_disabled().

File

./breakpoint.module, line 150
Manage breakpoints and breakpoint groups for responsive designs.

Code

function _breakpoint_delete_breakpoints($ids, $source_type) {
  $breakpoint_groups = entity_load_multiple('breakpoint_group', $ids);
  foreach ($breakpoint_groups as $breakpoint_group) {
    if ($breakpoint_group->sourceType == $source_type) {

      // Delete the automatically created breakpoint group.
      $breakpoint_group
        ->delete();

      // Get all breakpoints defined by this theme/module.
      $breakpoint_ids = drupal_container()
        ->get('config.storage')
        ->listAll('breakpoint.breakpoint.' . $source_type . '.' . $breakpoint_group
        ->id() . '.');
      $entity_info = entity_get_info('breakpoint');

      // Remove the breakpoint.breakpoint part of the breakpoint identifier.
      foreach ($breakpoint_ids as &$breakpoint_id) {
        $breakpoint_id = drupal_substr($breakpoint_id, drupal_strlen($entity_info['config prefix']) + 1);
      }
      $breakpoints = entity_load_multiple('breakpoint', $breakpoint_ids);

      // Make sure we only delete breakpoints defined by this theme/module.
      foreach ($breakpoints as $breakpoint) {
        if ($breakpoint->sourceType == $source_type && ($breakpoint->source = $breakpoint_group->id)) {
          $breakpoint
            ->delete();
        }
      }
    }
  }

  // Delete groups defined by a module/theme even if that module/theme didn't
  // define any breakpoints.
  foreach ($ids as $id) {

    // Delete all breakpoint groups defined by the theme or module.
    _breakpoint_delete_breakpoint_groups($id, $source_type);
  }
}