Account created on 12 September 2019, almost 5 years ago
  • Drupal Developer at DRUPAKΒ 
#

Merge Requests

Recent comments

πŸ‡΅πŸ‡°Pakistan sajideen

If We use the "simple" widget from inline entity form, for a required single-value reference, then the value is lost when we navigate to a new step.
we can achieve this issue if we use tempstore.

Set form state values in tempstore like:

$entity = $entity_form->getEntity();
if( $entity ) {
$entity_type_id = $entity->getEntityTypeId();
$entity_type_id = $entity_type_id."_data";
$value = $form_state->getValues();
$tempstore = \Drupal::service('tempstore.private')->get('simple_multistep');
$tempstore->set($entity_type_id, $value);
}

and then use inline entity form alter to set the form state values.
$tempstore = \Drupal::service('tempstore.private')->get('simple_multistep');
$stored_data = $tempstore->get($entity_type);
// Get the entity field manager service.
$entity_field_manager = \Drupal::service('entity_field.manager');
// Get the field definitions for the entity type.
$fields = $entity_field_manager->getFieldDefinitions($entity_form['#entity_type'], NULL);
// Process the fields as needed.
foreach ($fields as $field_name => $field_definition) {
// Check if the field is an inline entity form field.
if (isset($stored_data[$field_name][0]["inline_entity_form"])) {
$field_data = $stored_data[$field_name][0]["inline_entity_form"];
if (!empty($field_data)) {
foreach ($field_data as $delta => $field_values) {
// Set default values for the field.
if (isset($entity_form[$field_name][$delta]['widget'][0]['value'])) {
$entity_form[$field_name][$delta]['widget'][0]['value']['#default_value'] = isset($field_values[0]['value']) ? $field_values[0]['value'] : NULL;
}
}
}
}
}

πŸ‡΅πŸ‡°Pakistan sajideen

It's not working in the inline entity form simple widget. If I navigate to a new step, the previous step's form_state values are lost.

Production build 0.69.0 2024