You are here

public function ModerationStateWidget::storeValue in Lightning Workflow 8.3

Same name and namespace in other branches
  1. 8.2 modules/lightning_scheduler/src/Plugin/Field/FieldWidget/ModerationStateWidget.php \Drupal\lightning_scheduler\Plugin\Field\FieldWidget\ModerationStateWidget::storeValue()

Accesses the hidden input element and stores its value in the form state.

Parameters

array $element: The hidden input.

\Drupal\Core\Form\FormStateInterface $form_state: The form state to update.

File

modules/lightning_scheduler/src/Plugin/Field/FieldWidget/ModerationStateWidget.php, line 220

Class

ModerationStateWidget
Scheduler extension of Content Moderation's widget.

Namespace

Drupal\lightning_scheduler\Plugin\Field\FieldWidget

Code

public function storeValue(array $element, FormStateInterface $form_state) {
  if ($form_state
    ->getErrors()) {
    return;
  }
  $decoded = Json::decode($element['#value']);
  if (is_array($decoded)) {
    $transition_storage = $form_state
      ->getValue('transition_storage') ?: [];

    // Support multiple widgets on one form (e.g. Inline Entity Form).
    $uuid = $this->entity
      ->uuid();
    $transition_storage[$uuid] = $decoded;
    $form_state
      ->setValue('transition_storage', $transition_storage);
  }
  else {
    throw new \InvalidArgumentException('Expected value of ' . $element['#name'] . ' to be an array.');
  }
}