You are here

public function Breakpoint::isValid in Breakpoints 8

Check if the breakpoint is valid.

Throws

Drupal\breakpoint\InvalidBreakpointSourceTypeException

Drupal\breakpoint\InvalidBreakpointSourceException

Drupal\breakpoint\InvalidBreakpointNameException

Drupal\breakpoint\InvalidBreakpointMediaQueryException

See also

isValidMediaQuery()

1 call to Breakpoint::isValid()
Breakpoint::save in lib/Drupal/breakpoint/Breakpoint.php
Overrides Drupal\config\ConfigEntityBase::save().

File

lib/Drupal/breakpoint/Breakpoint.php, line 251
Definition of Drupal\breakpoint\Breakpoint.

Class

Breakpoint
Defines the Breakpoint entity.

Namespace

Drupal\breakpoint

Code

public function isValid() {

  // Check for illegal values in breakpoint 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,
    )));
  }

  // Check for illegal characters in breakpoint names.
  if (preg_match('/[^0-9a-z_\\-]/', $this->name)) {
    throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint name property. Breakpoint name property can only contain lowercase alphanumeric characters, underscores (_), and hyphens (-).", array(
      '@name' => $this->name,
    )));
  }
  return $this::isValidMediaQuery($this->mediaQuery);
}