예제 #1
0
 protected function setUp()
 {
     parent::setUp();
     // Create a telephone field storage and field for validation.
     FieldStorageConfig::create(array('field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone'))->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'])->save();
 }
예제 #2
0
 protected function setUp()
 {
     parent::setUp();
     $this->container->get('router.builder')->rebuild();
     $this->installEntitySchema('entity_test_rev');
     $this->createFieldWithStorage();
 }
예제 #3
0
 protected function setUp()
 {
     parent::setUp();
     // Create a 'test_field' field and storage for validation.
     FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field'))->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test'])->save();
 }
예제 #4
0
 /**
  * Sets up the test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_string_id');
     $this->installEntitySchema('taxonomy_term');
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('file');
     $this->installSchema('comment', ['comment_entity_statistics']);
     $this->installSchema('node', ['node_access']);
     $this->vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $this->vocabulary->save();
     $this->term = Term::create(['name' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $this->term->save();
     $this->entityStringId = EntityTestStringId::create(['id' => $this->randomMachineName()]);
     $this->entityStringId->save();
     // Use the util to create an instance.
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term');
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_entity_test_string_id', 'Test content entity reference with string ID', 'entity_test_string_id');
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_node', 'Test node entity reference', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user');
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment');
     $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     // Create the necessary formats.
     $this->installConfig(array('filter'));
     FilterFormat::create(array('format' => 'no_filters', 'filters' => array()))->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     $this->storage = \Drupal::entityManager()->getStorage('entity_test');
     $this->storageRev = \Drupal::entityManager()->getStorage('entity_test_rev');
     $this->storageUser = \Drupal::entityManager()->getStorage('user');
 }
 function setUp()
 {
     parent::setUp();
     $this->fieldStorageDefinition = array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field');
     $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $this->fieldStorage->save();
     $this->fieldDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test');
 }
 protected function setUp()
 {
     parent::setUp();
     // Module uninstall requires users_data tables.
     // @see drupal_flush_all_caches()
     // @see user_modules_uninstalled()
     $this->installSchema('user', array('users_data'));
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create a boolean field and storage for validation.
     FieldStorageConfig::create(array('field_name' => 'field_boolean', 'entity_type' => 'entity_test', 'type' => 'boolean'))->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_boolean', 'bundle' => 'entity_test'])->save();
     // Create a form display for the default form mode.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent('field_boolean', array('type' => 'boolean_checkbox'))->save();
 }
예제 #10
0
 protected function setUp()
 {
     parent::setUp();
     // Create number field storages and fields for validation.
     foreach (array('integer', 'float', 'decimal') as $type) {
         FieldStorageConfig::create(array('entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'type' => $type))->save();
         FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'bundle' => 'entity_test'])->save();
     }
 }
예제 #11
0
 protected function setUp()
 {
     parent::setUp();
     // Create a field with settings to validate.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_datetime', 'type' => 'datetime', 'entity_type' => 'entity_test', 'settings' => array('datetime_type' => 'date')));
     $field_storage->save();
     $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'entity_test', 'settings' => array('default_value' => 'blank')]);
     $field->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->container->get('router.builder')->rebuild();
     $this->fieldStorageDefinition = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three')));
     $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test']);
     $this->field->save();
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save();
 }
예제 #13
0
 protected function setUp()
 {
     parent::setUp();
     // Create a generic, external, and internal link fields for validation.
     FieldStorageConfig::create(['field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'link'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_GENERIC]])->save();
     FieldStorageConfig::create(['field_name' => 'field_test_external', 'entity_type' => 'entity_test', 'type' => 'link'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test_external', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_EXTERNAL]])->save();
     FieldStorageConfig::create(['field_name' => 'field_test_internal', 'entity_type' => 'entity_test', 'type' => 'link'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test_internal', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_INTERNAL]])->save();
 }
예제 #14
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('file', array('file_usage'));
     FieldStorageConfig::create(array('field_name' => 'file_test', 'entity_type' => 'entity_test', 'type' => 'file', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save();
     $this->directory = $this->getRandomGenerator()->name(8);
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'file_test', 'bundle' => 'entity_test', 'settings' => array('file_directory' => $this->directory)])->save();
     file_put_contents('public://example.txt', $this->randomMachineName());
     $this->file = File::create(['uri' => 'public://example.txt']);
     $this->file->save();
 }
예제 #15
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('file', array('file_usage'));
     FieldStorageConfig::create(array('entity_type' => 'entity_test', 'field_name' => 'image_test', 'type' => 'image', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'image_test', 'bundle' => 'entity_test'])->save();
     file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
     $this->image = File::create(['uri' => 'public://example.jpg']);
     $this->image->save();
     $this->imageFactory = $this->container->get('image.factory');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create a field and a storage of type 'test_field', on the 'entity_test'
     // entity type.
     $this->entityType = 'entity_test';
     $this->bundle = 'entity_test';
     $this->createFieldWithStorage('', $this->entityType, $this->bundle);
     $this->entityManager = $this->container->get('entity.manager');
     // Create a second field on 'entity_test_rev'.
     $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
 }
예제 #17
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(['field']);
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('file');
     $this->installSchema('file', array('file_usage'));
     $this->entityType = 'entity_test';
     $this->bundle = $this->entityType;
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     FieldStorageConfig::create(array('entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'type' => 'image', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save();
     FieldConfig::create(['entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'bundle' => $this->bundle, 'settings' => ['file_extensions' => 'jpg']])->save();
     $this->display = entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, ['type' => 'image', 'label' => 'hidden']);
     $this->display->save();
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('language'));
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $this->entityType = 'entity_test';
     $this->fieldStorageDefinition = array('field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'test_field', 'cardinality' => 4);
     $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $this->fieldStorage->save();
     $this->fieldDefinition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test');
     $this->field = FieldConfig::create($this->fieldDefinition);
     $this->field->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
예제 #19
0
 protected function setUp()
 {
     parent::setUp();
     $this->fieldStorages = array();
     $this->entities = array();
     $this->entitiesByBundles = array();
     // Create two bundles.
     $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
     foreach ($this->bundles as $name => $desc) {
         entity_test_create_bundle($name, $desc);
     }
     // Create two field storages.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'bf_1', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     $field_storage = FieldStorageConfig::create(array('field_name' => 'bf_2', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     // For each bundle, create each field, and 10 entities with values for the
     // fields.
     foreach ($this->bundles as $bundle) {
         foreach ($this->fieldStorages as $field_storage) {
             FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $bundle])->save();
         }
         for ($i = 0; $i < 10; $i++) {
             $entity = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId)->create(array('type' => $bundle));
             foreach ($this->fieldStorages as $field_storage) {
                 $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
             }
             $entity->save();
         }
     }
     $this->entities = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId)->loadMultiple();
     foreach ($this->entities as $entity) {
         // This test relies on the entities having stale field definitions
         // so that the deleted field can be accessed on them. Access the field
         // now, so that they are always loaded.
         $entity->bf_1->value;
         // Also keep track of the entities per bundle.
         $this->entitiesByBundles[$entity->bundle()][$entity->id()] = $entity;
     }
 }
예제 #20
0
 /**
  * {@inheritdoc}
  *
  * This sets up the entity_test and user types to use our example
  * field plugins.
  */
 protected function setUp()
 {
     parent::setUp();
     $type_manager = $this->container->get('entity_type.manager');
     // Set up our entity_type and user type for our new field:
     $type_manager->getStorage('field_storage_config')->create(['field_name' => 'field_fieldnote', 'entity_type' => 'entity_test', 'type' => 'field_permission_example_fieldnote'])->save();
     $type_manager->getStorage('field_config')->create(['entity_type' => 'entity_test', 'field_name' => 'field_fieldnote', 'bundle' => 'entity_test'])->save();
     // Create a form display for the default form mode, and
     // add our field type.
     $type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default', 'status' => TRUE])->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save();
     // Now do this for the user type.
     $type_manager->getStorage('field_storage_config')->create(['field_name' => 'user_fieldnote', 'entity_type' => 'user', 'type' => 'field_permission_example_fieldnote'])->save();
     $type_manager->getStorage('field_config')->create(['entity_type' => 'user', 'field_name' => 'user_fieldnote', 'bundle' => 'user'])->save();
     // Fetch a form display for a user. This may already exist, so check as
     // Core does.
     // @see https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_get_form_display/8
     $entity_form_display = $type_manager->getStorage('entity_form_display')->load('user.user.default');
     if (empty($entity_form_display)) {
         $entity_form_display = $type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'user', 'bundle' => 'user', 'mode' => 'default', 'status' => TRUE]);
     }
     // And add our fancy field to that display:
     $entity_form_display->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save();
 }
예제 #21
0
 protected function setUp()
 {
     parent::setUp();
     // Create a field and its storage.
     $this->fieldName = 'test_field';
     $this->label = $this->randomMachineName();
     $this->cardinality = 4;
     $field_storage = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $this->cardinality);
     $field = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->label);
     $this->displayOptions = array('default' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomMachineName())), 'teaser' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomMachineName())));
     FieldStorageConfig::create($field_storage)->save();
     FieldConfig::create($field)->save();
     // Create a display for the default view mode.
     entity_get_display($field['entity_type'], $field['bundle'], 'default')->setComponent($this->fieldName, $this->displayOptions['default'])->save();
     // Create a display for the teaser view mode.
     EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
     entity_get_display($field['entity_type'], $field['bundle'], 'teaser')->setComponent($this->fieldName, $this->displayOptions['teaser'])->save();
     // Create an entity with values.
     $this->values = $this->_generateTestFieldValues($this->cardinality);
     $this->entity = EntityTest::create();
     $this->entity->{$this->fieldName}->setValue($this->values);
     $this->entity->save();
 }
예제 #22
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
 }
예제 #23
0
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('comment', ['comment_entity_statistics']);
     $this->installConfig(['comment']);
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     \Drupal::service('router.builder')->rebuild();
 }