/** * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { $contact_type_is_active = empty($entity_bundle); // Load the contact type entity. if (!empty($entity_bundle)) { /* @var \Drupal\crm_core_contact\Entity\ContactType $contact_type_entity */ $contact_type_entity = ContactType::load($entity_bundle); $contact_type_is_active = $contact_type_entity->status(); } return AccessResult::allowedIf($contact_type_is_active)->andIf(AccessResult::allowedIfHasPermissions($account, ['administer crm_core_contact entities', 'create crm_core_contact entities', 'create crm_core_contact entities of bundle ' . $entity_bundle], 'OR')); }
/** * Tests CRUD of contacts. * * @todo Check if working once https://drupal.org/node/2239969 got committed. */ public function testContact() { $this->installEntitySchema('user'); $type = ContactType::create(array('type' => 'test')); $type->primary_fields = []; $type->save(); // Create. $contact = Contact::create(array('type' => $type->type)); $this->assertEqual(SAVED_NEW, $contact->save(), 'Contact saved.'); // Load. $contact_load = Contact::load($contact->id()); $uuid = $contact_load->uuid(); $this->assertTrue(!empty($uuid), 'Loaded contact has uuid.'); // Delete. $contact->delete(); $contact_load = Contact::load($contact->id()); $this->assertNull($contact_load, 'Contact deleted.'); }
/** * Loads all enabled Contact Types. * * @return \Drupal\crm_core_contact\Entity\ContactType[] * An array of contact types indexed by their IDs. */ public static function loadActive() { $ids = \Drupal::entityQuery('crm_core_contact')->condition('status', TRUE)->execute(); return ContactType::loadMultiple($ids); }