当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldConfig::getTargetBundle方法代码示例

本文整理汇总了PHP中Drupal\field\Entity\FieldConfig::getTargetBundle方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldConfig::getTargetBundle方法的具体用法?PHP FieldConfig::getTargetBundle怎么用?PHP FieldConfig::getTargetBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\field\Entity\FieldConfig的用法示例。


在下文中一共展示了FieldConfig::getTargetBundle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createField

 /**
  * Creates a date test field.
  */
 protected function createField()
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $type = $this->getTestFieldType();
     $widget_type = $formatter_type = $type . '_default';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $type, 'settings' => ['datetime_type' => DateRangeItem::DATETIME_TYPE_DATE]]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE]);
     $this->field->save();
     EntityFormDisplay::load('entity_test.entity_test.default')->setComponent($field_name, ['type' => $widget_type])->save();
     $this->displayOptions = ['type' => $formatter_type, 'label' => 'hidden', 'settings' => ['format_type' => 'medium'] + $this->defaultSettings];
     EntityViewDisplay::create(['targetEntityType' => $this->field->getTargetEntityTypeId(), 'bundle' => $this->field->getTargetBundle(), 'mode' => 'full', 'status' => TRUE])->setComponent($field_name, $this->displayOptions)->save();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:16,代码来源:DateTestBase.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('user');
     $this->installConfig(['system']);
     $this->installSchema('system', ['sequences', 'key_value']);
     // Add a datetime range field.
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'daterange', 'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATE]]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE]);
     $this->field->save();
     $display_options = ['type' => 'daterange_default', 'label' => 'hidden', 'settings' => ['format_type' => 'fallback', 'separator' => 'UNTRANSLATED']];
     EntityViewDisplay::create(['targetEntityType' => $this->field->getTargetEntityTypeId(), 'bundle' => $this->field->getTargetBundle(), 'mode' => 'default', 'status' => TRUE])->setComponent($this->fieldStorage->getName(), $display_options)->save();
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:18,代码来源:SeparatorTranslationTest.php

示例3: testDatelistWidget

 /**
  * Tests Date List Widget functionality.
  */
 function testDatelistWidget()
 {
     $field_name = $this->fieldStorage->getName();
     // Change the field to a datetime field.
     $this->fieldStorage->setSetting('datetime_type', 'datetime');
     $this->fieldStorage->save();
     // Change the widget to a datelist widget.
     entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')->setComponent($field_name, array('type' => 'datetime_datelist', 'settings' => array('increment' => 1, 'date_order' => 'YMD', 'time_type' => '12')))->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-year\"]", NULL, 'Year element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-year", '', 'No year selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-month\"]", NULL, 'Month element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-month", '', 'No month selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-day\"]", NULL, 'Day element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-day", '', 'No day selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-hour\"]", NULL, 'Hour element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '', 'No hour selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-minute\"]", NULL, 'Minute element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-minute", '', 'No minute selected.');
     $this->assertNoFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-second\"]", NULL, 'Second element not found.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-ampm\"]", NULL, 'AMPM element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-ampm", '', 'No ampm selected.');
     // Submit a valid date and ensure it is accepted.
     $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15);
     $edit = array();
     // Add the ampm indicator since we are testing 12 hour time.
     $date_value['ampm'] = 'am';
     foreach ($date_value as $part => $value) {
         $edit["{$field_name}[0][value][{$part}]"] = $value;
     }
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     $this->assertOptionSelected("edit-{$field_name}-0-value-year", '2012', 'Correct year selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-month", '12', 'Correct month selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-day", '31', 'Correct day selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '5', 'Correct hour selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-minute", '15', 'Correct minute selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-ampm", 'am', 'Correct ampm selected.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:46,代码来源:DateTimeFieldTest.php

示例4: testDatelistWidget

 /**
  * Tests Date List Widget functionality.
  */
 function testDatelistWidget()
 {
     $field_name = $this->fieldStorage->getName();
     // Ensure field is set to a date only field.
     $this->fieldStorage->setSetting('datetime_type', 'date');
     $this->fieldStorage->save();
     // Change the widget to a datelist widget.
     entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')->setComponent($field_name, array('type' => 'datetime_datelist', 'settings' => array('date_order' => 'YMD')))->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     // Assert that Hour and Minute Elements do not appear on Date Only
     $this->assertNoFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-hour\"]", NULL, 'Hour element not found on Date Only.');
     $this->assertNoFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-minute\"]", NULL, 'Minute element not found on Date Only.');
     // Go to the form display page to assert that increment option does not appear on Date Only
     $fieldEditUrl = 'entity_test/structure/entity_test/form-display';
     $this->drupalGet($fieldEditUrl);
     // Click on the widget settings button to open the widget settings form.
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $xpathIncr = "//select[starts-with(@id, \"edit-fields-{$field_name}-settings-edit-form-settings-increment\")]";
     $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.');
     // Change the field to a datetime field.
     $this->fieldStorage->setSetting('datetime_type', 'datetime');
     $this->fieldStorage->save();
     // Change the widget to a datelist widget.
     entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')->setComponent($field_name, array('type' => 'datetime_datelist', 'settings' => array('increment' => 1, 'date_order' => 'YMD', 'time_type' => '12')))->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Go to the form display page to assert that increment option does appear on Date Time
     $fieldEditUrl = 'entity_test/structure/entity_test/form-display';
     $this->drupalGet($fieldEditUrl);
     // Click on the widget settings button to open the widget settings form.
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $this->assertFieldByXPath($xpathIncr, NULL, 'Increment element found for Date and time.');
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-year\"]", NULL, 'Year element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-year", '', 'No year selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-month\"]", NULL, 'Month element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-month", '', 'No month selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-day\"]", NULL, 'Day element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-day", '', 'No day selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-hour\"]", NULL, 'Hour element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '', 'No hour selected.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-minute\"]", NULL, 'Minute element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-minute", '', 'No minute selected.');
     $this->assertNoFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-second\"]", NULL, 'Second element not found.');
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-ampm\"]", NULL, 'AMPM element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-ampm", '', 'No ampm selected.');
     // Submit a valid date and ensure it is accepted.
     $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15);
     $edit = array();
     // Add the ampm indicator since we are testing 12 hour time.
     $date_value['ampm'] = 'am';
     foreach ($date_value as $part => $value) {
         $edit["{$field_name}[0][value][{$part}]"] = $value;
     }
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     $this->assertOptionSelected("edit-{$field_name}-0-value-year", '2012', 'Correct year selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-month", '12', 'Correct month selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-day", '31', 'Correct day selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '5', 'Correct hour selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-minute", '15', 'Correct minute selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-ampm", 'am', 'Correct ampm selected.');
     // Test the widget using increment other than 1 and 24 hour mode.
     entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')->setComponent($field_name, array('type' => 'datetime_datelist', 'settings' => array('increment' => 15, 'date_order' => 'YMD', 'time_type' => '24')))->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     // Other elements are unaffected by the changed settings.
     $this->assertFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-hour\"]", NULL, 'Hour element found.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '', 'No hour selected.');
     $this->assertNoFieldByXPath("//*[@id=\"edit-{$field_name}-0-value-ampm\"]", NULL, 'AMPM element not found.');
     // Submit a valid date and ensure it is accepted.
     $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 17, 'minute' => 15);
     $edit = array();
     foreach ($date_value as $part => $value) {
         $edit["{$field_name}[0][value][{$part}]"] = $value;
     }
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     $this->assertOptionSelected("edit-{$field_name}-0-value-year", '2012', 'Correct year selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-month", '12', 'Correct month selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-day", '31', 'Correct day selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-hour", '17', 'Correct hour selected.');
     $this->assertOptionSelected("edit-{$field_name}-0-value-minute", '15', 'Correct minute selected.');
     // Test the widget for partial completion of fields.
     entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')->setComponent($field_name, array('type' => 'datetime_datelist', 'settings' => array('increment' => 1, 'date_order' => 'YMD', 'time_type' => '24')))->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Test the widget for validation notifications.
     foreach ($this->datelistDataProvider() as $data) {
         list($date_value, $expected) = $data;
         // Display creation form.
//.........这里部分代码省略.........
开发者ID:papillon-cendre,项目名称:d8,代码行数:101,代码来源:DateTimeFieldTest.php

示例5: testTranslatableFieldSaveLoad

 /**
  * Test translatable fields storage/retrieval.
  */
 function testTranslatableFieldSaveLoad()
 {
     // Enable field translations for nodes.
     field_test_entity_info_translatable('node', TRUE);
     $entity_type = \Drupal::entityManager()->getDefinition('node');
     $this->assertTrue($entity_type->isTranslatable(), 'Nodes are translatable.');
     // Prepare the field translations.
     $entity_type_id = 'entity_test';
     field_test_entity_info_translatable($entity_type_id, TRUE);
     $entity = entity_create($entity_type_id, array('type' => $this->field->getTargetBundle()));
     $field_translations = array();
     $available_langcodes = array_keys($this->container->get('language_manager')->getLanguages());
     $entity->langcode->value = reset($available_langcodes);
     foreach ($available_langcodes as $langcode) {
         $field_translations[$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality());
         $entity->getTranslation($langcode)->{$this->fieldName}->setValue($field_translations[$langcode]);
     }
     // Save and reload the field translations.
     $entity = $this->entitySaveReload($entity);
     // Check if the correct values were saved/loaded.
     foreach ($field_translations as $langcode => $items) {
         $result = TRUE;
         foreach ($items as $delta => $item) {
             $result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->fieldName}[$delta]->value;
         }
         $this->assertTrue($result, format_string('%language translation correctly handled.', array('%language' => $langcode)));
     }
     // Test default values.
     $field_name_default = Unicode::strtolower($this->randomMachineName() . '_field_name');
     $field_storage_definition = $this->fieldStorageDefinition;
     $field_storage_definition['field_name'] = $field_name_default;
     $field_storage = entity_create('field_storage_config', $field_storage_definition);
     $field_storage->save();
     $field_definition = $this->fieldDefinition;
     $field_definition['field_storage'] = $field_storage;
     $field_definition['default_value'] = array(array('value' => rand(1, 127)));
     $field = entity_create('field_config', $field_definition);
     $field->save();
     $translation_langcodes = array_slice($available_langcodes, 0, 2);
     asort($translation_langcodes);
     $translation_langcodes = array_values($translation_langcodes);
     $values = array('type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]);
     $entity = entity_create($entity_type_id, $values);
     foreach ($translation_langcodes as $langcode) {
         $values[$this->fieldName][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality());
         $entity->getTranslation($langcode, FALSE)->{$this->fieldName}->setValue($values[$this->fieldName][$langcode]);
     }
     $field_langcodes = array_keys($entity->getTranslationLanguages());
     sort($field_langcodes);
     $this->assertEqual($translation_langcodes, $field_langcodes, 'Missing translations did not get a default value.');
     // @todo Test every translation once the Entity Translation API allows for
     //   multilingual defaults.
     $langcode = $entity->language()->getId();
     $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $field->default_value, format_string('Default value correctly populated for language %language.', array('%language' => $langcode)));
     // Check that explicit empty values are not overridden with default values.
     foreach (array(NULL, array()) as $empty_items) {
         $values = array('type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]);
         $entity = entity_create($entity_type_id, $values);
         foreach ($translation_langcodes as $langcode) {
             $values[$this->fieldName][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality());
             $entity->getTranslation($langcode)->{$this->fieldName}->setValue($values[$this->fieldName][$langcode]);
             $entity->getTranslation($langcode)->{$field_name_default}->setValue($empty_items);
             $values[$field_name_default][$langcode] = $empty_items;
         }
         foreach ($entity->getTranslationLanguages() as $langcode => $language) {
             $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $empty_items, format_string('Empty value correctly populated for language %language.', array('%language' => $langcode)));
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:72,代码来源:TranslationTest.php


注:本文中的Drupal\field\Entity\FieldConfig::getTargetBundle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。