You are here

public function StateItem::isValid in State Machine 8

Gets whether the current state is valid.

Drupal separates field validation into a separate step, allowing an invalid state to be set before validation is invoked. At that point validation has no access to the previous value, so it can't determine if the transition is allowed. Thus, the field item must track the state changes internally, and answer via this method if the current state is valid.

Return value

bool TRUE if the current state is valid, FALSE otherwise.

Overrides StateItemInterface::isValid

See also

\Drupal\state_machine\Plugin\Validation\Constraint\StateConstraintValidator

File

src/Plugin/Field/FieldType/StateItem.php, line 159

Class

StateItem
Plugin implementation of the 'state' field type.

Namespace

Drupal\state_machine\Plugin\Field\FieldType

Code

public function isValid() {
  $allowed_states = $this
    ->getAllowedStates($this->originalValue);
  return isset($allowed_states[$this->value]);
}