You are here

public function BreakpointGroup::isValid in Breakpoints 8

Check if the breakpoint group is valid.

Return value

true

Throws

Drupal\breakpoint\InvalidBreakpointSourceTypeException

Drupal\breakpoint\InvalidBreakpointSourceException

1 call to BreakpointGroup::isValid()
BreakpointGroup::save in lib/Drupal/breakpoint/BreakpointGroup.php
Overrides Drupal\Core\Entity::save().

File

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

Class

BreakpointGroup
Defines the BreakpointGroup entity.

Namespace

Drupal\breakpoint

Code

public function isValid() {

  // Check for illegal values in breakpoint group source type.
  if (!in_array($this->sourceType, array(
    Breakpoint::SOURCE_TYPE_CUSTOM,
    Breakpoint::SOURCE_TYPE_MODULE,
    Breakpoint::SOURCE_TYPE_THEME,
  ))) {
    throw new InvalidBreakpointSourceTypeException(format_string('Invalid source type @source_type', array(
      '@source_type' => $this->sourceType,
    )));
  }

  // Check for illegal characters in breakpoint source.
  if (preg_match('/[^a-z_]+/', $this->source)) {
    throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint source property. Breakpoint source property can only contain lowercase letters and underscores.", array(
      '@source' => $this->source,
    )));
  }
  return TRUE;
}