You are here

public function GroupEditForm::form in Entity Share 8

Same name and namespace in other branches
  1. 8.3 modules/entity_share_server/src/Form/GroupEditForm.php \Drupal\entity_share_server\Form\GroupEditForm::form()
  2. 8.2 modules/entity_share_server/src/Form/GroupEditForm.php \Drupal\entity_share_server\Form\GroupEditForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/entity_share_server/src/Form/GroupEditForm.php, line 24

Class

GroupEditForm
Class GroupEditForm.

Namespace

Drupal\entity_share_server\Form

Code

public function form(array $form, FormStateInterface $form_state) {

  // Check if the group exists.
  if (!$this
    ->groupIdExists()) {
    drupal_set_message($this
      ->t('There is no group with the ID @id in this channel', [
      '@id' => $this
        ->getgroupId(),
    ]), 'error');
    return [];
  }
  $form = parent::form($form, $form_state);

  /** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
  $channel = $this->entity;
  $channel_groups = $channel
    ->get('channel_groups');
  $group_id = $this
    ->getgroupId();
  if (is_null($channel_groups)) {
    $channel_groups = [];
  }
  $form['group_id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('ID'),
    '#default_value' => $group_id,
    '#machine_name' => [
      'exists' => [
        $this,
        'groupExists',
      ],
    ],
    '#disabled' => TRUE,
  ];
  $form['conjunction'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Conjunction'),
    '#options' => $this
      ->getConjunctionOptions(),
    '#default_value' => $channel_groups[$group_id]['conjunction'],
    '#required' => TRUE,
  ];
  $form['memberof'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Parent group'),
    '#options' => $this
      ->getGroupOptions($group_id),
    '#empty_option' => $this
      ->t('Select a group'),
    '#default_value' => isset($channel_groups[$group_id]['memberof']) ? $channel_groups[$group_id]['memberof'] : '',
  ];
  return $form;
}