public function BreakpointGroup::isValid

Checks if the breakpoint group is valid.

Return value

bool Returns TRUE if the breakpoint group is valid.

Throws

\Drupal\breakpoint\InvalidBreakpointSourceTypeException

\Drupal\breakpoint\InvalidBreakpointSourceException

Overrides BreakpointGroupInterface::isValid

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

File

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

Class

BreakpointGroup
Defines the BreakpointGroup entity.

Namespace

Drupal\breakpoint\Plugin\Core\Entity

Code

public function isValid() {

  // Check for illegal values in breakpoint group 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 group source.
  if (preg_match('/[^a-z_]+/', $this->source) || empty($this->source)) {
    throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint group source property. Breakpoint group source property can only contain lowercase letters and underscores.", array(
      '@source' => $this->source,
    )));
  }

  // Check for illegal characters in breakpoint group name.
  if (preg_match('/[^a-z0-9_]+/', $this->name || empty($this->name))) {
    throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint group name property. Breakpoint group name property can only contain lowercase letters, numbers and underscores.", array(
      '@name' => $this->name,
    )));
  }
  return TRUE;
}