You are here

function bbb_node_form_alter in BigBlueButton 8

Implements hook_form_alter().

File

modules/bbb_node/bbb_node.module, line 85
Big Blue Button - Enables universities and colleges to deliver a high-quality learning experience.

Code

function bbb_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Node type settings form
  switch ($form_id) {
    case 'node_type_edit_form':
    case 'node_type_add_form':
      $manager = \Drupal::entityTypeManager();
      $storage = $manager
        ->getStorage('bbb_node_type');

      /** @var \Drupal\node\NodeTypeInterface $node_type */
      $node_type = $form_state
        ->getFormObject()
        ->getEntity();

      /** @var \Drupal\bbb_node\Service\NodeMeeting $node_meeting */
      $node_meeting = \Drupal::service('bbb_node.meeting');
      if (!$node_meeting
        ->isTypeOf($node_type)) {
        return;
      }
      if ($form_id == 'node_type_edit_form') {
        $id = $node_type
          ->id();
        $label = $node_type
          ->label();
        $entity = $storage
          ->load($id);
        if (!$entity) {
          $entity = $storage
            ->create([
            'id' => $id,
            'label' => $label,
          ]);
        }
      }
      else {
        $entity = $storage
          ->create();
      }
      $bbb_form = $manager
        ->getFormObject($entity
        ->getEntityTypeId(), 'edit');
      $bbb_form
        ->setEntity($entity);
      $form['bbb'] = $bbb_form
        ->buildForm([], new FormState());
      if (!empty($form['bbb']['#submit'])) {
        $form['#submit'][] = array_pop($form['bbb']['#submit']);
      }
      if (!empty($form['actions']['submit']['#validate']) && !empty($form['bbb']['actions']['submit']['#validate'])) {
        $form['actions']['submit']['#validate'] = array_merge($form['actions']['submit']['#validate'], $form['bbb']['actions']['submit']['#validate']);
      }
      if (!empty($form['actions']['submit']['#submit']) && !empty($form['bbb']['actions']['submit']['#submit'])) {
        $form['actions']['submit']['#submit'] = array_merge($form['actions']['submit']['#submit'], $form['bbb']['actions']['submit']['#submit']);
        $form['actions']['submit']['#submit'][] = [
          $bbb_form,
          'saveEntity',
        ];
      }
      $form['bbb']['actions']['#access'] = FALSE;
      break;
    default:
      break;
  }
}