public function Breakpoint::isValid

Checks if the breakpoint is valid.

Throws

\Drupal\breakpoint\InvalidBreakpointSourceTypeException

\Drupal\breakpoint\InvalidBreakpointSourceException

\Drupal\breakpoint\InvalidBreakpointNameException

\Drupal\breakpoint\InvalidBreakpointMediaQueryException

Overrides BreakpointInterface::isValid

See also

isValidMediaQuery()

1 call to Breakpoint::isValid()
Breakpoint::save in drupal/core/modules/breakpoint/lib/Drupal/breakpoint/Plugin/Core/Entity/Breakpoint.php
Overrides Drupal\config\ConfigEntityBase::save().

File

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

Class

Breakpoint
Defines the Breakpoint entity.

Namespace

Drupal\breakpoint\Plugin\Core\Entity

Code

public function isValid() {

  // Check for illegal values in breakpoint source type.
  if (!in_array($this->sourceType, array(
    Breakpoint::SOURCE_TYPE_USER_DEFINED,
    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);
}