public function contacts($parameters = array()) { $url = self::contacts_uri(self::id()); $response = new Response(ContactList::get($url, $parameters)); foreach ($response->items as &$value) { $value = new Contact(new Response($value)); } return $response; }
/** * Saves the changes made in the bulk edit into the dataObject * * @return Redirect */ public function doAddToList($data, $form) { $className = $this->gridField->list->dataClass; $singleton = singleton($className); $return = array(); if (isset($data['RecordIDs'])) { $ids = explode(",", $data['RecordIDs']); } else { $ids = array(); } $list_id = isset($data['ContactListID']) ? $data['ContactListID'] : 0; $list = ContactList::get()->byID($list_id); try { foreach ($ids as $record_id) { if ($list_id) { $record = DataObject::get_by_id($className, $record_id); if ($record->hasMethod("Lists")) { $list->Contacts()->add($record); $list->write(); } $return[] = $record->ID; } } } catch (Exception $e) { $controller = $this->controller; $form->sessionMessage($e->getResult()->message(), 'bad', false); $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) { return $form->forTemplate(); }, 'default' => function () use(&$controller) { return $controller->redirectBack(); })); if ($controller->getRequest()->isAjax()) { $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm'); } return $responseNegotiator->respond($controller->getRequest()); } $controller = $this->getToplevelController(); $form = $controller->EditForm(); $message = "Added " . count($return) . " contacts to mailing list '{$list->Title}'"; $form->sessionMessage($message, 'good', false); // Changes to the record properties might've excluded the record from // a filtered list, so return back to the main view if it can't be found $link = $controller->Link(); $controller->getRequest()->addHeader('X-Pjax', 'Content'); return $controller->redirect($link); }