本文整理汇总了PHP中Drupal\field\Entity\FieldConfig::save方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldConfig::save方法的具体用法?PHP FieldConfig::save怎么用?PHP FieldConfig::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\field\Entity\FieldConfig
的用法示例。
在下文中一共展示了FieldConfig::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmailField
/**
* Tests email field.
*/
function testEmailField()
{
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email'));
$this->fieldStorage->save();
$this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test']);
$this->field->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'email_default', 'settings' => array('placeholder' => 'example@example.com')))->save();
// Create a display for the full view mode.
entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'email_mailto'))->save();
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget found.');
$this->assertRaw('placeholder="example@example.com"');
// Submit a valid email address and ensure it is accepted.
$value = 'test@example.com';
$edit = array("{$field_name}[0][value]" => $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->assertRaw($value);
// Verify that a mailto link is displayed.
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertLinkByHref('mailto:test@example.com');
}
示例2: testBlockFields
/**
* Checks block edit functionality.
*/
public function testBlockFields()
{
$this->drupalLogin($this->adminUser);
$this->blockType = $this->createBlockContentType('link');
// Create a field with settings to validate.
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => drupal_strtolower($this->randomMachineName()), 'entity_type' => 'block_content', 'type' => 'link', 'cardinality' => 2));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'link', 'settings' => array('title' => DRUPAL_OPTIONAL)));
$this->field->save();
entity_get_form_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link_default'))->save();
entity_get_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link', 'label' => 'hidden'))->save();
// Create a block.
$this->drupalGet('block/add/link');
$edit = array('info[0][value]' => $this->randomMachineName(8), $this->fieldStorage->getName() . '[0][url]' => 'http://example.com', $this->fieldStorage->getName() . '[0][title]' => 'Example.com');
$this->drupalPostForm(NULL, $edit, t('Save'));
$block = entity_load('block_content', 1);
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
// Place the block.
$instance = array('id' => drupal_strtolower($edit['info[0][value]']), 'settings[label]' => $edit['info[0][value]'], 'region' => 'sidebar_first');
$this->drupalPostForm($url, $instance, t('Save block'));
// Navigate to home page.
$this->drupalGet('<front>');
$this->assertLinkByHref('http://example.com');
$this->assertText('Example.com');
}
示例3: testBooleanField
/**
* Tests boolean field.
*/
function testBooleanField()
{
$on = $this->randomMachineName();
$off = $this->randomMachineName();
$label = $this->randomMachineName();
// Create a field with settings to validate.
$field_name = drupal_strtolower($this->randomMachineName());
$this->field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean', 'settings' => array('on_label' => $on, 'off_label' => $off)));
$this->field_storage->save();
$this->field = FieldConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE));
$this->field->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox'))->save();
// Create a display for the full view mode.
entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'boolean'))->save();
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
$this->assertRaw($on);
// Submit and ensure it is accepted.
$edit = array("{$field_name}[value]" => 1);
$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)));
// Verify that boolean value is displayed.
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->drupalSetContent(drupal_render($content));
$this->assertRaw('<div class="field-item">' . $on . '</div>');
// Test the display_label option.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox', 'settings' => array('display_label' => TRUE)))->save();
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
$this->assertNoRaw($on);
$this->assertText($this->field->label());
// Go to the form display page and check if the default settings works as
// expected.
$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->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox available.'));
// Enable setting.
$edit = array('fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1);
$this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update");
$this->drupalPostForm(NULL, NULL, 'Save');
// Go again to the form display page and check if the setting
// is stored and has the expected effect.
$this->drupalGet($fieldEditUrl);
$this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
$this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
$this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox is available'));
$this->assertFieldByXPath('*//input[@id="edit-fields-' . $field_name . '-settings-edit-form-settings-display-label" and @value="1"]', TRUE, t('Display label changes label of the checkbox'));
// Test the boolean field settings.
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage');
$this->assertFieldById('edit-field-storage-settings-on-label', $on);
$this->assertFieldById('edit-field-storage-settings-off-label', $off);
}
示例4: setUp
/**
* {@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();
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installSchema('system', array('router'));
$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 = entity_create('field_storage_config', $this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->field = entity_create('field_config', array('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();
}
示例6: testUriField
/**
* Tests URI field.
*/
public function testUriField()
{
$label = $this->randomMachineName();
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'uri']);
$this->fieldStorage->save();
$this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE, 'settings' => ['size' => 123, 'placeholder' => '']]);
$this->field->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, ['type' => 'uri'])->save();
}
示例7: 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();
}
示例8: setUp
protected function setUp()
{
parent::setUp();
$web_user = $this->drupalCreateUser(array('access content', 'view test entity', 'administer entity_test content', 'administer content types', 'administer node fields'));
$this->drupalLogin($web_user);
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'datetime', 'settings' => array('datetime_type' => 'date')));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE));
$this->field->save();
entity_get_form_display($this->field->entity_type, $this->field->bundle, 'default')->setComponent($field_name, array('type' => 'datetime_default'))->save();
$this->displayOptions = array('type' => 'datetime_default', 'label' => 'hidden', 'settings' => array('format_type' => 'medium'));
entity_get_display($this->field->entity_type, $this->field->bundle, 'full')->setComponent($field_name, $this->displayOptions)->save();
}
示例9: 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();
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Create content type with unlimited text field.
$this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
// Create the unlimited text field.
$this->fieldName = 'field_views_testing_group_rows';
$this->fieldStorage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]);
$this->fieldStorage->save();
// Create an instance of the text field on the content type.
$this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => $this->nodeType->id()]);
$this->field->save();
$edit = ['title' => $this->randomMachineName(), $this->fieldName => ['a', 'b', 'c']];
$this->drupalCreateNode($edit);
}
示例11: setUp
/**
* {@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();
}
}
示例12: setUp
protected function setUp()
{
parent::setUp();
$this->installConfig(array('language'));
$this->field_name = drupal_strtolower($this->randomMachineName());
$this->entity_type = 'entity_test';
$this->field_storage_definition = array('field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE);
$this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition);
$this->fieldStorage->save();
$this->field_definition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test');
$this->field = entity_create('field_config', $this->field_definition);
$this->field->save();
for ($i = 0; $i < 3; ++$i) {
ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
}
}
示例13: createField
/**
* Creates a geofield field storage and field.
*
* @param string $entity_type
* Entity type for which the field should be created.
*/
protected function createField($entity_type)
{
// Create a field .
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => 'geofield_field', 'entity_type' => $entity_type, 'type' => 'geofield', 'settings' => array('backend' => 'geofield_backend_default')));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $entity_type));
$this->field->save();
}
示例14: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$entity_type = 'entity_test_rev';
$this->fieldName = strtolower($this->randomMachineName());
$this->fieldCardinality = 4;
$this->fieldStorage = FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => $this->fieldCardinality));
$this->fieldStorage->save();
$this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => $entity_type]);
$this->field->save();
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = \Drupal::entityManager()->getStorage($entity_type)->getTableMapping();
$this->tableMapping = $table_mapping;
$this->table = $table_mapping->getDedicatedDataTableName($this->fieldStorage);
$this->revisionTable = $table_mapping->getDedicatedRevisionTableName($this->fieldStorage);
}
示例15: createField
/**
* Creates a text_with_summary field storage and field.
*
* @param string $entity_type
* Entity type for which the field should be created.
*/
protected function createField($entity_type)
{
// Create a field .
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => 'summary_field', 'entity_type' => $entity_type, 'type' => 'text_with_summary', 'settings' => array('max_length' => 10)));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $entity_type));
$this->field->save();
}