You are here

public function BreakpointGroup::revert in Breakpoints 8

Revert a breakpoint group after it has been overridden.

Return value

Drupal\breakpoint\BreakpointGroup

File

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

Class

BreakpointGroup
Defines the BreakpointGroup entity.

Namespace

Drupal\breakpoint

Code

public function revert() {
  if (!$this->overridden || $this->sourceType === Breakpoint::SOURCE_TYPE_CUSTOM) {
    return FALSE;
  }

  // Reload all breakpoints from theme or module.
  switch ($this->sourceType) {
    case Breakpoint::SOURCE_TYPE_THEME:
      $reloaded_group = breakpoint_group_reload_from_theme($this
        ->id());
      if ($reloaded_group) {
        $this->breakpoints = $reloaded_group->breakpoints;
        $this->overridden = FALSE;
        $this
          ->save();
      }
      break;
    case Breakpoint::SOURCE_TYPE_MODULE:
      $reloaded_group = breakpoint_group_reload_from_module($this->source, $this
        ->id());
      if ($reloaded_group) {
        $this->breakpoints = $reloaded_group->breakpoints;
        $this->overridden = FALSE;
        $this
          ->save();
      }
      else {
        throw new \Exception("something went wrong :s");
      }
      break;
  }
  return $this;
}