You are here

function workflow_get_workflow_state_names in Workflow 8

Same name and namespace in other branches
  1. 7.2 workflow.module \workflow_get_workflow_state_names()

Get an options list for workflow states.

Parameters

mixed $wid: The Workflow ID.

bool $grouped: Indicates if the value must be grouped per workflow. This influences the rendering of the select_list options.

Return value

array An array of $sid => state->label(), grouped per Workflow.

4 calls to workflow_get_workflow_state_names()
WorkflowState::init in src/Plugin/views/filter/WorkflowState.php
Overrides \Drupal\views\Plugin\views\HandlerBase::init().
WorkflowStateListBuilder::buildForm in src/WorkflowStateListBuilder.php
Form constructor.
WorkflowStateListBuilder::buildRow in src/WorkflowStateListBuilder.php
Builds a row for an entity in the entity listing.
WorkflowTransitionElement::transitionElement in src/Element/WorkflowTransitionElement.php
Generate an element.

File

./workflow.module, line 351
Support workflows made up of arbitrary states.

Code

function workflow_get_workflow_state_names($wid = '', $grouped = FALSE) {
  $options = [];

  // @todo Implement $add parameter.
  //
  // @todo Follow Options pattern.
  // @see callback_allowed_values_function()
  // @see options_allowed_values()
  // Get the (user-dependent) options.
  // Since this function is only used in UI, it is save to use the global $user.
  $user = workflow_current_user();

  /** @var \Drupal\workflow\Entity\Workflow[] $workflows */
  $workflows = Workflow::loadMultiple($wid ? [
    $wid,
  ] : NULL);

  // Do not group if only 1 Workflow is configured or selected.
  $grouped = count($workflows) == 1 ? FALSE : $grouped;
  foreach ($workflows as $wid => $workflow) {

    /** @var \Drupal\workflow\Entity\WorkflowState $state */
    $state = WorkflowState::create([
      'wid' => $wid,
    ]);
    $workflow_options = $state
      ->getOptions(NULL, '', $user, FALSE);
    if (!$grouped) {
      $options += $workflow_options;
    }
    else {

      // Make a group for each Workflow.
      $options[$workflow
        ->label()] = $workflow_options;
    }
  }
  return $options;
}