You are here

public function Workflow::getFirstSid in Workflow 8

Gets the first valid state ID, after the creation state.

Uses WorkflowState::getOptions(), because this does an access check. The first State ID is user-dependent!

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity at hand. May be NULL (E.g., on a Field settings page).

string $field_name:

\Drupal\Core\Session\AccountInterface $user:

bool $force:

Return value

string A State ID.

Overrides WorkflowInterface::getFirstSid

File

src/Entity/Workflow.php, line 305

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function getFirstSid(EntityInterface $entity, $field_name, AccountInterface $user, $force = FALSE) {
  $creation_state = $this
    ->getCreationState();
  $options = $creation_state
    ->getOptions($entity, $field_name, $user, $force);
  if ($options) {
    $keys = array_keys($options);
    $sid = $keys[0];
  }
  else {

    // This should never happen, but it did during testing.
    $this
      ->messenger()
      ->addError($this
      ->t('There are no workflow states available. Please notify your site administrator.'));
    $sid = 0;
  }
  return $sid;
}