You are here

protected function ChannelForm::buildGroupsTable in Entity Share 8

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

Helper function to generate group form elements.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Throws

\LogicException

\Exception

1 call to ChannelForm::buildGroupsTable()
ChannelForm::form in modules/entity_share_server/src/Form/ChannelForm.php
Gets the actual form array to be built.

File

modules/entity_share_server/src/Form/ChannelForm.php, line 312

Class

ChannelForm
Class ChannelForm.

Namespace

Drupal\entity_share_server\Form

Code

protected function buildGroupsTable(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
  $channel = $this->entity;
  $channel_groups = $channel
    ->get('channel_groups');
  if (is_null($channel_groups)) {
    $channel_groups = [];
  }
  $form['channel_groups'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Groups'),
  ];
  if ($channel
    ->isNew()) {
    $form['channel_groups']['group_message'] = [
      '#markup' => $this
        ->t("It will be possible to add groups after the channel's creation."),
    ];
  }
  else {
    $form['channel_groups']['group_actions'] = [
      '#type' => 'actions',
      '#weight' => -5,
    ];
    $form['channel_groups']['group_actions']['group_add'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Add a new group'),
      '#url' => Url::fromRoute('entity_share_server.group_add_form', [
        'channel' => $channel
          ->id(),
      ]),
      '#attributes' => [
        'class' => [
          'button',
          'button--primary',
        ],
      ],
    ];
    $header = [
      'id' => [
        'data' => $this
          ->t('ID'),
      ],
      'conjunction' => [
        'data' => $this
          ->t('Conjunction'),
      ],
      'memberof' => [
        'data' => $this
          ->t('Parent group'),
      ],
      'operations' => [
        'data' => $this
          ->t('Operations'),
      ],
    ];
    $rows = [];
    foreach ($channel_groups as $group_id => $group) {
      $operations = [
        '#type' => 'dropbutton',
        '#links' => [
          'edit' => [
            'title' => $this
              ->t('Edit'),
            'url' => Url::fromRoute('entity_share_server.group_edit_form', [
              'channel' => $channel
                ->id(),
              'group' => $group_id,
            ]),
          ],
          'delete' => [
            'title' => $this
              ->t('Delete'),
            'url' => Url::fromRoute('entity_share_server.group_delete_form', [
              'channel' => $channel
                ->id(),
              'group' => $group_id,
            ]),
          ],
        ],
      ];
      $row = [
        'id' => $group_id,
        'conjunction' => $group['conjunction'],
        'memberof' => isset($group['memberof']) ? $group['memberof'] : '',
        'operations' => $this->renderer
          ->render($operations),
      ];
      $rows[] = $row;
    }
    $form['channel_groups']['group_table'] = [
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#empty' => $this
        ->t('There is currently no group for this channel.'),
    ];
  }
}