コード例 #1
0
ファイル: FieldTest.php プロジェクト: Wylbur/gj
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     // Create the article content type with a text field.
     $node_type = NodeType::create(['type' => 'article']);
     $node_type->save();
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'type' => 'text']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test field']);
     $field->save();
     $this->testFormat = FilterFormat::create(['format' => 'test', 'weight' => 1, 'filters' => ['filter_html_escape' => ['status' => TRUE]]]);
     $this->testFormat->save();
 }
コード例 #2
0
 /**
  * Sets up the test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('system', ['key_value_expire']);
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $this->format = FilterFormat::create(['format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => ['filter_align' => ['status' => TRUE], 'filter_caption' => ['status' => TRUE]]]);
     $this->format->save();
     // Set up text editor.
     $editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn', 'image_upload' => ['max_size' => 100, 'scheme' => 'public', 'directory' => '', 'status' => TRUE]]);
     $editor->save();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     node_add_body_field($type);
     $this->installEntitySchema('user');
     \Drupal::service('router.builder')->rebuild();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $this->installEntitySchema('taxonomy_term');
     // Create the article content type with a text field.
     $node_type = NodeType::create(['type' => 'article']);
     $node_type->save();
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'type' => 'text']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test field']);
     $field->save();
     // Create a reference field with the same name on user.
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'user', 'type' => 'entity_reference']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'user', 'bundle' => 'user', 'label' => 'Test field']);
     $field->save();
     $this->testFormat = FilterFormat::create(['format' => 'test', 'weight' => 1, 'filters' => ['filter_html_escape' => ['status' => TRUE]]]);
     $this->testFormat->save();
     // Create a multi-value list_string field.
     $field_storage = FieldStorageConfig::create(['field_name' => 'test_list', 'entity_type' => 'node', 'type' => 'list_string', 'cardinality' => 2, 'settings' => ['allowed_values' => ['key1' => 'value1', 'key2' => 'value2']]]);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_name' => 'test_list', 'entity_type' => 'node', 'bundle' => 'article'])->save();
     // Add an untranslatable node reference field.
     FieldStorageConfig::create(['field_name' => 'test_reference', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => ['target_type' => 'node'], 'translatable' => FALSE])->save();
     FieldConfig::create(['field_name' => 'test_reference', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test reference'])->save();
     // Add an untranslatable taxonomy term reference field.
     $this->vocabulary = $this->createVocabulary();
     FieldStorageConfig::create(['field_name' => 'test_term_reference', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => ['target_type' => 'taxonomy_term'], 'translatable' => FALSE])->save();
     FieldConfig::create(['field_name' => 'test_term_reference', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test term reference', 'settings' => ['handler' => 'default:taxonomy_term', 'handler_settings' => ['target_bundles' => [$this->vocabulary->id() => $this->vocabulary->id()]]]])->save();
     // Add a field to terms of the created vocabulary.
     $storage = FieldStorageConfig::create(['field_name' => 'term_field', 'entity_type' => 'taxonomy_term', 'type' => 'text']);
     $storage->save();
     $field = FieldConfig::create(['field_name' => 'term_field', 'entity_type' => 'taxonomy_term', 'bundle' => $this->vocabulary->id()]);
     $field->save();
     // Add a second language.
     $language = ConfigurableLanguage::create(['id' => 'de', 'label' => 'German']);
     $language->save();
 }