You are here

public function ApiProductAccessControlForm::submitForm in Apigee Edge 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/ApiProductAccessControlForm.php, line 175

Class

ApiProductAccessControlForm
Provides a form for configuring visible API products in Drupal.

Namespace

Drupal\apigee_edge\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $rid_product_map = [];
  foreach ($form_state
    ->getValue([
    'access',
    'role_names',
  ], []) as $rid => $name) {

    // Do not store roles with by pass permission in the attribute
    // unnecessarily.
    if (!$form_state
      ->getValue([
      'access',
      'roles_with_bypass',
      $rid,
    ], FALSE)) {
      $rid_product_map[$rid] = array_filter($form_state
        ->getValue([
        'access',
        'visibility',
        $rid,
      ], []));
    }
  }

  // Ensure that we always keep these 3 keys in config object.
  $visibility_rid_map = array_fill_keys(array_keys($form_state
    ->getValue([
    'access',
    'visibility',
    'options',
  ])), []);
  foreach ($rid_product_map as $rid => $products) {
    foreach (array_keys($products) as $product) {
      $visibility_rid_map[$product][$rid] = $rid;
    }
  }
  $this
    ->config('apigee_edge.api_product_settings')
    ->set('access', $visibility_rid_map)
    ->save();
  parent::submitForm($form, $form_state);
}