/**
  * Render a list of entries in the database.
  */
 public function listOfMembers($grouping)
 {
     $content = array();
     $content['add_existing_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_grouping_members\\EAGroupingMembersAddForm', $grouping);
     $content['add_new_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_people\\EAPeopleAddForm');
     $content['message'] = array('#markup' => $this->t('Generate a list of all members of the grouping.'));
     $header = array(array('data' => $this->t('Nickname'), 'field' => 'person.nickname'), array('data' => $this->t('First name'), 'field' => 'person.firstname'), array('data' => $this->t('Last names'), 'field' => 'person.lastnames'), $this->t('Edit'), $this->t('Membership'));
     // Only show members of this grouping.
     $filter = array('gid' => $grouping->gid);
     // Construct table rows.
     $rows = array();
     foreach ($entries = EAGroupingMembersStorage::loadSorted($header, $filter) as $member) {
         // Construct rows.
         $row = array();
         $row['data']['nickname'] = $member->nickname;
         $row['data']['firstname'] = $member->firstname;
         $row['data']['lastnames'] = $member->lastnames;
         // Format edit link.
         $edit_link_url = Url::fromRoute('ea_grouping_members.edit', array('grouping' => $grouping->gid, 'member' => $member->gmid));
         $edit_link = \Drupal::l($this->t('Edit'), $edit_link_url);
         $row['data']['edit_link'] = $edit_link;
         // Format cancel link.
         $cancel_link_url = Url::fromRoute('ea_grouping_members.cancel', array('grouping' => $grouping->gid, 'member' => $member->gmid));
         $cancel_link = \Drupal::l($this->t('Cancel'), $cancel_link_url);
         $row['data']['cancel_link'] = $cancel_link;
         // Add data to row.
         $rows[] = $row;
     }
     $content['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No members added yet.'));
     $content['pager'] = array('#type' => 'pager');
     return $content;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     foreach ($values['existing_members'] as $pid) {
         // Save the submitted entry.
         $return = EAGroupingMembersStorage::insert(array('pid' => $pid, 'gid' => $values['gid']));
     }
     drupal_set_message(t('Added members'));
 }
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     if (!empty($value)) {
         $results = EAGroupingMembersStorage::load(array('gmid' => $value), TRUE);
         if (!empty($results)) {
             return $results[0];
         }
     }
     return NULL;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $gid = $form_state->getValue('gid');
     $pid = $form_state->getValue('pid');
     // Delete the entry.
     EAGroupingMembersStorage::delete(array('gid' => $gid, 'pid' => $pid));
     $person = EAPeopleStorage::load(array('pid' => $pid));
     if (!empty($person)) {
         $entry = $person[0];
         drupal_set_message(t('Cancelled membership for @name', array('@name' => implode(' ', array($entry->nickname, $entry->firstname, $entry->lastnames)))));
     } else {
         drupal_set_message(t('Cancelled membership for non-existant person'));
     }
     // Redirect the user to the list controller when complete.
     $form_state->setRedirectUrl($this->getCancelUrl());
 }