You are here

public function ContentBuilder::updateFormSortingOptions in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::updateFormSortingOptions()
  2. 8.8 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::updateFormSortingOptions()
  3. 10.3.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::updateFormSortingOptions()
  4. 10.1.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::updateFormSortingOptions()
  5. 10.2.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::updateFormSortingOptions()

Update the sorting field after a plugin choice change.

File

modules/social_features/social_content_block/src/ContentBuilder.php, line 369

Class

ContentBuilder
Class ContentBuilder.

Namespace

Drupal\social_content_block

Code

public function updateFormSortingOptions($form, FormStateInterface $form_state) {
  $parents = [
    'field_sorting',
  ];
  if ($form_state
    ->has('layout_builder__component')) {
    $parents = array_merge([
      'settings',
      'block_form',
    ], $parents);
  }

  // Check that the currently selected value is valid and change it otherwise.
  $value_parents = array_merge($parents, [
    '0',
    'value',
  ]);
  $sort_value = $form_state
    ->getValue($value_parents);
  $options = NestedArray::getValue($form, array_merge($parents, [
    'widget',
    '#options',
  ]));
  if ($sort_value === NULL || !isset($options[$sort_value])) {

    // Unfortunately this has already triggered a validation error.
    $form_state
      ->clearErrors();
    $form_state
      ->setValue($value_parents, key($options));
  }
  return NestedArray::getValue($form, $parents);
}