protected function WorkflowItem::allowedValuesString in Workflow 8
Generates a string representation of an array of 'allowed values'.
This string format is suitable for edition in a textarea.
Parameters
\Drupal\Core\Entity\EntityInterface[] $states: An array of WorkflowStates, where array keys are values and array values are labels.
Return value
string The string representation of the $states array:
- Values are separated by a carriage return.
- Each value is in the format "value|label" or "value".
Overrides ListItemBase::allowedValuesString
1 call to WorkflowItem::allowedValuesString()
- WorkflowItem::storageSettingsForm in src/
Plugin/ Field/ FieldType/ WorkflowItem.php - Implements hook_field_settings_form() -> ConfigFieldItemInterface::settingsForm().
File
- src/
Plugin/ Field/ FieldType/ WorkflowItem.php, line 278
Class
- WorkflowItem
- Plugin implementation of the 'workflow' field type.
Namespace
Drupal\workflow\Plugin\Field\FieldTypeCode
protected function allowedValuesString($states) {
$lines = [];
$wid = $this
->getSetting('workflow_type');
$previous_wid = -1;
/** @var \Drupal\workflow\Entity\WorkflowState $state */
foreach ($states as $key => $state) {
// Only show enabled states.
if ($state
->isActive()) {
// Show a Workflow name between Workflows, if more then 1 in the list.
if (!$wid && $previous_wid != $state
->getWorkflowId()) {
$previous_wid = $state
->getWorkflowId();
$lines[] = $state
->getWorkflow()
->label() . "'s states: ";
}
$label = $this
->t('@label', [
'@label' => $state
->label(),
]);
$lines[] = " {$key}|{$label}";
}
}
return implode("\n", $lines);
}