/** * Test the UI. */ public function testUI() { $this->drupalLogin($this->createUser()); // Test the basic list. $this->drupalGet('/people'); // Add entry. $this->drupalPostForm('/people', array('nickname' => 'Noname', 'firstname' => 'John', 'lastnames' => 'Doe'), t('Add person')); // Check that person is added. $this->drupalGet('/people'); $this->assertPattern("/John/", "Text 'John' found in table"); // Test updating a person. $result = \Drupal\ea_people\EAPeopleStorage::load(array('firstname' => 'John')); $entry = (array) $result[0]; $this->assertTrue($entry, 'Found an entry in the table with first name = "John".'); $pid = $entry['pid']; $this->drupalPostForm('/people/' . $pid, array('nickname' => 'None', 'firstname' => 'Jane', 'lastnames' => 'Doe', 'do_not_contact' => TRUE), t('Update person')); // Check that person name is updated. $this->drupalGet('/people'); $this->assertPattern("/Jane/", "Text 'Jane' found in table"); // Test deleting a person. $this->drupalPostForm('/people/' . $pid . '/delete', array(), t('Delete person')); // Check that the person is deleted. $result = \Drupal\ea_people\EAPeopleStorage::load(array('firstname' => 'Jane')); $this->assertEqual(count($result), 0, 'Found zero entries in the table with first name = "Jane".'); }
/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { if (!empty($value)) { $results = EAPeopleStorage::load(array('pid' => $value)); if (!empty($results)) { return $results[0]; } } return NULL; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $pid = $form_state->getValue('pid'); $persons = EAPeopleStorage::load(array('pid' => $pid)); if (!empty($persons)) { $person = $persons[0]; // Delete the person. EAPeopleStorage::delete(array('pid' => $pid)); drupal_set_message(t('Deleted @nickname @firstname @lastnames', array('@nickname' => $person->nickname, '@firstname' => $person->firstname, '@lastnames' => $person->lastnames))); } else { drupal_set_message(t('Person not found')); } // Redirect the user to the list controller when complete. $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * {@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()); }