You are here

private static function WorkflowManager::getCreationStateId in Workflow 8

Gets the creation sid for a given $entity and $field_name.

Is a helper function for:

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

string $field_name:

Return value

string The ID of the creation State for the Workflow of the field.

1 call to WorkflowManager::getCreationStateId()
WorkflowManager::getPreviousStateId in src/Entity/WorkflowManager.php
Gets the previous state ID of a given entity.

File

src/Entity/WorkflowManager.php, line 269

Class

WorkflowManager
Manages entity type plugin definitions.

Namespace

Drupal\workflow\Entity

Code

private static function getCreationStateId(EntityInterface $entity, $field_name) {
  $sid = '';

  /** @var \Drupal\Core\Config\Entity\ConfigEntityBase $entity */

  /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_config */
  $field_config = $entity
    ->get($field_name)
    ->getFieldDefinition();
  $field_storage = $field_config
    ->getFieldStorageDefinition();
  $wid = $field_storage
    ->getSetting('workflow_type');
  if ($wid) {

    /** @var \Drupal\workflow\Entity\Workflow $workflow */
    $workflow = Workflow::load($wid);
    if (!$workflow) {
      \Drupal::messenger()
        ->addError(t('Workflow %wid cannot be loaded. Contact your system administrator.', [
        '%wid' => $wid,
      ]));
    }
    else {
      $sid = $workflow
        ->getCreationSid();
    }
  }
  return $sid;
}