You are here

public static function BreakpointGroup::ImportBreakpointGroup in Breakpoints 8

Import breakpoint groups from theme or module.

Parameters

string $source: Source of the breakpoint group: theme_key or module name.

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

string $id: Identifier of the breakpoint group.

string $label: Human readable name of the breakpoint group.

array $breakpoints: Array of breakpoints, using either the short name or the full name.

Return value

\Drupal\breakpoint\BreakpointGroup|false Return the new breakpoint group containing all breakpoints.

2 calls to BreakpointGroup::ImportBreakpointGroup()
breakpoint_group_reload_from_module in ./breakpoint.module
Reload breakpoint groups as they were defined in the module.
_breakpoint_import_breakpoint_groups in ./breakpoint.module
Import breakpoint groups from theme or module.

File

lib/Drupal/breakpoint/BreakpointGroup.php, line 302
Definition of Drupal\breakpoint\BreakpointGroup.

Class

BreakpointGroup
Defines the BreakpointGroup entity.

Namespace

Drupal\breakpoint

Code

public static function ImportBreakpointGroup($source, $source_type, $id, $label, $breakpoints) {

  // Use the existing breakpoint group if it exists.
  $breakpoint_group = entity_load('breakpoint_group', $source_type . '.' . $id);
  if (!$breakpoint_group) {
    $breakpoint_group = entity_create('breakpoint_group', array(
      'id' => $id,
      'label' => !empty($label) ? $label : $id,
      'source' => $source,
      'sourceType' => $source_type,
    ));
  }
  else {

    // Reset label.
    $breakpoint_group->label = !empty($label) ? $label : $id;
  }

  // Add breakpoints to the group.
  foreach ($breakpoints as $breakpoint_name) {

    // Check if breakpoint exists, assume short name.
    $breakpoint = entity_load('breakpoint', $source_type . '.' . $source . '.' . $breakpoint_name);

    // If the breakpoint doesn't exist, try using the full name.
    if (!$breakpoint) {
      $breakpoint = entity_load('breakpoint', $breakpoint_name);
    }
    if ($breakpoint) {

      // Add breakpoint to group.
      $breakpoint_group->breakpoints[$breakpoint
        ->id()] = $breakpoint;
    }
  }
  return $breakpoint_group;
}