function _breakpoint_import_breakpoint_groups

Import breakpoint groups from theme or module.

Parameters

string $source: The theme or module name

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

3 calls to _breakpoint_import_breakpoint_groups()
BreakpointThemeTest::testThemeBreakpointGroupModule in drupal/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php
Test the breakpoints defined by the custom group in the module.
_breakpoint_modules_enabled in drupal/core/modules/breakpoint/breakpoint.module
Import breakpoints from all new enabled modules.
_breakpoint_theme_enabled in drupal/core/modules/breakpoint/breakpoint.module
Import breakpoints from all new enabled themes.

File

drupal/core/modules/breakpoint/breakpoint.module, line 157
Manage breakpoints and breakpoint groups for responsive designs.

Code

function _breakpoint_import_breakpoint_groups($source, $source_type) {
  $breakpoint_groups = config($source . '.breakpoint_groups');
  if ($breakpoint_groups) {
    foreach ($breakpoint_groups
      ->get() as $group_name => $data) {

      // Breakpoints is mandatory, extra check since this is coming from config.
      if (isset($data['breakpoints']) && !empty($data['breakpoints'])) {

        // Create a new breakpoint group if it doesn't exist.
        $breakpoint_group = _breakpoint_group_create_or_load($group_name, isset($data['label']) ? $data['label'] : $group_name, $source, $source_type);

        // Add the breakpoints.
        $breakpoint_group
          ->addBreakpoints($data['breakpoints']);
        $breakpoint_group
          ->save();
      }
      else {
        throw new \Exception('Illegal config file detected.');
      }
    }
  }
}