You are here

public function StateItem::applyDefaultValue in State Machine 8

Applies the default value.

Parameters

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Return value

$this Returns itself to allow for chaining.

Overrides Map::applyDefaultValue

File

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

Class

StateItem
Plugin implementation of the 'state' field type.

Namespace

Drupal\state_machine\Plugin\Field\FieldType

Code

public function applyDefaultValue($notify = TRUE) {
  if ($workflow = $this
    ->getWorkflow()) {
    $states = $workflow
      ->getStates();
    $initial_state = reset($states);
    $this
      ->setValue([
      'value' => $initial_state
        ->getId(),
    ], $notify);
  }
  return $this;
}