/**
  * {@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'));
 }
Example #2
0
 /**
  * Tests CRUD of contact types.
  */
 public function testContactType()
 {
     $type = 'dog';
     // Create.
     $contact_type = ContactType::create(array('type' => $type));
     $this->assertTrue(isset($contact_type->type) && $contact_type->type == $type, 'New contact type type exists.');
     // @todo Check if this still must be the case.
     //    $this->assertTrue($contact_type->locked, t('New contact type has locked set to TRUE.'));
     $contact_type->name = $this->randomMachineName();
     $contact_type->description = $this->randomString();
     $contact_type->primary_fields = [];
     $this->assertEqual(SAVED_NEW, $contact_type->save(), 'Contact type saved.');
     // Load.
     $contact_type_load = ContactType::load($type);
     $this->assertEqual($contact_type->type, $contact_type_load->type, 'Loaded contact type has same type.');
     $this->assertEqual($contact_type->name, $contact_type_load->name, 'Loaded contact type has same name.');
     $this->assertEqual($contact_type->description, $contact_type_load->description, 'Loaded contact type has same description.');
     $uuid = $contact_type_load->uuid();
     $this->assertTrue(!empty($uuid), 'Loaded contact type has uuid.');
     // Delete.
     $contact_type_load->delete();
     $contact_type_load = ContactType::load($type);
     $this->assertNull($contact_type_load, 'Contact type deleted.');
 }