public function BreakpointGroup::addBreakpoints

Adds one or more breakpoints to this group.

The breakpoint name is either the machine_name or the id of a breakpoint.

Parameters

array $breakpoints: Array containing breakpoints keyed by their id.

File

drupal/core/modules/breakpoint/lib/Drupal/breakpoint/Plugin/Core/Entity/BreakpointGroup.php, line 183
Definition of Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup.

Class

BreakpointGroup
Defines the BreakpointGroup entity.

Namespace

Drupal\breakpoint\Plugin\Core\Entity

Code

public function addBreakpoints($breakpoints) {
  foreach ($breakpoints as $breakpoint_name) {

    // Check if breakpoint exists, assume $breakpoint_name is a machine name.
    $breakpoint = entity_load('breakpoint', $this->sourceType . '.' . $this->source . '.' . $breakpoint_name);

    // If the breakpoint doesn't exist, assume $breakpoint_name is an id.
    if (!$breakpoint) {
      $breakpoint = entity_load('breakpoint', $breakpoint_name);
    }

    // If the breakpoint doesn't exists, do not add it.
    if ($breakpoint) {

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