1

I am a bit new for Drupal and currently working on Drupal8. I need to implement custom restrictions for workflow. Basically i want to get the submitted value of moderation_state filed in mymodule_form_alte

Here are the things that i have tried but all returns Null. The strange thing is that the below method works for node but do not work for block_content

 function mymodule_form_alter($form, &$form_state, $form_id) {
   $formSate = $form_state->getValue('moderation_state')[0]['valye'];
   var_dump($formState); // Output : Null

   $formSate = $form['moderation_state']['widget']['#default_value'];
   var_dump($formState); // Output : return the default value of dropdown not the one that i have selected
}

Here is the moderation_state field enter image description here

1 Answer 1

2

all most there try the following

// Get the current  entity.
$entity = $form_state->getFormObject()->getEntity();
$moderation_state = $entity->get('moderation_state')->getString();
// Do the things.

or in a submit or validation thing try to

// use dump() as it is way better 
dump($form_state->getValues()) // <-- and find in the array 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.